【问题标题】:my htaccess file doesn't work to load css我的 htaccess 文件无法加载 css
【发布时间】:2014-12-26 13:20:22
【问题描述】:

我试图找到一些答案,但它对我不起作用,所以我决定在这里问: 我是 codeigniter 的新手,看了一些教程后,我最终得到了这个 .htaccess 代码。

 <IfModule mod_rewrite.c>
      RewriteEngine On

  RewriteBase /myprojectname
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond $1 !^(index.php|css|robots.txt)
  RewriteRule ^(.*)$ index.php/$1 [L]

</IfModule>

<IfModule !mod_rewrite.c>
 ErrorDocument 404 /index.php
</IfModule>

我在本地主机上使用 xampp,我的问题是我无法在我的视图中加载我的 css

 <link rel="stylesheet" href="css/metro-bootstrap.css">

实际上我在 RewriteCond $1 !^(index.php|css|robots.txt) 中包含 css 根是这样的

/
-application
-css
-js
-font
-system
-.htaccess
-index.php

【问题讨论】:

  • RewriteCond %{REQUEST_FILENAME} !-f 应该已经确保不会重写现有文件。尝试删除排除 index.php、css 和 robots.txt 的行。
  • RewriteCond $1 行需要删除。
  • 事实上,RewriteCond 一点意义都没有……
  • 真,删除RewriteCond $1

标签: php html css .htaccess codeigniter


【解决方案1】:

您不必在该行中包含 css 和 robots.txt,因为 RewriteCond %{REQUEST_FILENAME} !-f 会处理它(基本上它说如果它不是文件则重写 - '!-f' 部分),实际上你可以删除RewriteCond $1 !^(index.php|css|robots.txt)。如果那你的css还是不行,使用&lt;?php echo base_url();?&gt;css/metro-bootstrap.css这行代码,base_url()表示你项目中的基本路径。

【讨论】:

    【解决方案2】:

    您可以在 .htaccess 中定义基础

        Options +FollowSymLinks
        RewriteEngine on
        RewriteBase /name of the path base
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-09
      • 2016-02-09
      • 2016-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多