codeigniter .htaccess代码未加载CSS,图像 [英] codeigniter .htaccess code not loading css, images
问题描述
我正在使用codeigniter在其网站上提供的htaccess。
一切正常的文件,但是当我在URL后使用 /
时,一切都搞砸了。
说我的域名为 www.example.com/mycontroller
可以正常使用,但 www.example.com/mycontroller /
弄乱了所有东西,没有样式,没有图像等等。
I am using the htaccess provided by codeigniter in their website.
Everything works file, but when i use a /
after the url, everything gets messed up.
say my domain is www.example.com/mycontroller
this will work fine but www.example.com/mycontroller/
makes every thing messed up, no style no image and all that.
我通过使用 base_url()解决了这个问题> code>在样式表和图像等的链接前面。但是没有其他方法,这样我就不必遍历每张图像并添加
base_url()
。
I solved the issue by using base_url()
in front of the links for stylesheet and images etc. But isnt there any other way so that I dont have to go through every image and link to add base_url()
.
.htaccess文件包含
The .htaccess file contains
RewriteEngine on
RewriteCond $1 !^(index\.php|css|images|robots\.txt)
RewriteRule ^(.*)$ ./index.php/$1 [L]
推荐答案
您应允许文件和文件夹通过
You should allow files and folders to pass
RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond $1 !^(index\.php|css|images|robots\.txt)
RewriteRule ^(.*)$ ./index.php/$1 [L]
是的,哟您应该添加 base_url
,否则您的应用程序的可移植性差,维护成为噩梦
And yes, you should add base_url
, otherwise your application is less portable and maintenance becomes a nightmare
这篇关于codeigniter .htaccess代码未加载CSS,图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!