my htaccess file doesn't work to load css

2019-09-19 18:55发布

问题:

i tried to find some answers but it doesnt work for me so i decided to ask here: im new to codeigniter, after watching some few tutorials i end up with this .htaccess code.

 <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>

im using xampp on localhost, my problem is that i cant load my css in my view

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

when in fact i include css in RewriteCond $1 !^(index.php|css|robots.txt) root looks like this

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

回答1:

You don't have to include css and robots.txt in that line because RewriteCond %{REQUEST_FILENAME} !-f takes care of it (basically it says Rewrite if it is NOT a file - '!-f' part), actually you can delete RewriteCond $1 !^(index.php|css|robots.txt). If then your css still doesn't work, use <?php echo base_url();?>css/metro-bootstrap.css this line of code, base_url() indicates base path in your project.



回答2:

You can define the base in the .htaccess

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