【问题标题】:codeigniter css htaccess, can't read filecodeigniter css htaccess,无法读取文件
【发布时间】:2011-12-14 20:59:40
【问题描述】:

我的 codeigniter 应用程序的根目录中有一个名为 /css 的目录,它包含文件 style.css。当我使用 href="<?php echo base_url();?>css/styles.css" 链接到文件时,我的 css 没有运行,显示为 html。

我在网上看到我需要修改我的 .htaccess 文件才能做到这一点,很多文章都解释了如何做,但这些方法对我不起作用。

如何使用下面的 htaccess 代码启用对以下文件夹 /images、/js、/css 的读取。

我正在使用 codeigniters 默认的 htaccess 代码来删除 index.php

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Submitted by: Fabdrol
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]

</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule>  

【问题讨论】:

  • 嗯,嗯,我并没有真正关注你:这是预期的行为。如果您直接链接到样式表,您会看到该样式表。你还想让它做什么?
  • 我可以看到样式表,但由于某种原因,codeigniter 没有将其读取为 css 并将 html 添加到它的顶部。
  • 你的意思是:#blockthing{bunchof:css;} ?
  • 是的,在底部显示 div id="container">

    遇到错误

    您提交的 URI 包含不允许的字符。

  • 你有那个链接吗...因为我不确定你想让 htaccess 做什么? CSS 代码不应该“运行”

标签: php css .htaccess codeigniter directory


【解决方案1】:

试试这个,它的工作原理。

  <link rel="stylesheet" href="<?php echo base_url();?>css/style.css" type="text/css" />

【讨论】:

    猜你喜欢
    • 2016-04-14
    • 2011-10-09
    • 1970-01-01
    • 1970-01-01
    • 2017-01-26
    • 2013-07-06
    • 1970-01-01
    • 2014-12-26
    • 2014-09-06
    相关资源
    最近更新 更多