我的htaccess文件无法加载CSS [英] my htaccess file doesn't work to load css
问题描述
我试图找到一些答案,但是它对我不起作用,所以我决定在这里问:
是codeigniter的新手,在看了一些教程后,我最终得到了这个.htaccess代码。
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在本地主机上使用xampp,我的问题是我无法在视图中加载CSS
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">
实际上我在 RewriteCond $ 1中包括css!^(index.php | css | robots.txt)
根看起来像这样
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
推荐答案
您不必在该行中包含css和robots.txt,因为 RewriteCond%{REQUEST_FILENAME}!-f
会处理它(基本上说如果不是文件,则显示Rewrite-'!-f'部分),实际上您可以删除 RewriteCond $ 1!^(index.php | css | robots.txt)
。如果您的CSS仍然无法使用,请使用<?php echo base_url();?> css / metro-bootstrap.css
这行代码, base_url()
表示项目中的基本路径。
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.
这篇关于我的htaccess文件无法加载CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!