htaccess代码没有加载css,图像


codeigniter .htaccess code not loading css, images

我在他们的网站上使用codeigniter提供的htaccess。所有的东西都是文件,但当我在url后面使用/时,一切都会变得一团糟。假设我的域是www.example.com/mycontroller,这会很好,但www.example.com/mycontroller/会把每件事都搞砸,没有风格,没有图像等等。

我通过在样式表和图像等的链接前使用base_url()解决了这个问题。但是没有其他方法可以让我不必遍历每个图像和链接来添加base_url()吗。

.htaccess文件包含

RewriteEngine on
RewriteCond $1 !^(index'.php|css|images|robots'.txt)
RewriteRule ^(.*)$ ./index.php/$1 [L]

您应该允许文件和文件夹通过

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,否则您的应用程序的可移植性会降低,维护将成为的噩梦

尝试检查请求是否指向文件或目录:

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

如果你没有一些真正好的理由,你可以链接到图像或css文件的基本目录。