我的htaccess文件没有';无法加载css


my htaccess file doesn't work to load css

我试图找到一些答案,但对我来说不起作用,所以我决定在这里问:我是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>

我在localhost上使用examplep,我的问题是我无法在视图中加载css

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

当我在RewriteCond $1 !^(index.php|css|robots.txt)中包含css时root看起来像这个

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

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

您可以在.htaccess 中定义基础

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