htaccess重写后加载图像

时间:2013-11-01 23:01:49

标签: apache .htaccess mod-rewrite url-rewriting rewrite

首先为标题写得不好道歉。无法用一个班轮解释这个问题。

我有一个简单的htaccess规则设置,有一些花哨的网址。我还使用它来组合并使用控制器加载我的所有css文件。

htaccess如下

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(style\.css) Asset [L]

RewriteRule ^(.*)$ index.php?rt=$1 [L,QSA]

index.php是一个路由到正确控制器的简单路由器,正如您在调用style.css时所看到的那样,它将请求传输到Asset Controller。我遇到的问题是如何使用css文件加载图像。重写条件也应用于图像,这是我想要避免的。

是否有人遇到类似的问题?

提前非常感谢任何帮助。

1 个答案:

答案 0 :(得分:2)

将.htaccess更改为

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?rt=$1&%{QUERY_STRING} [L]

在控制器中检查它是否是$ _GET ['rt']

中的style.css

如果要在mod_rewrite级别将style.css更改为Asset,请使用:

RewriteEngine on
RewriteCond %{REQUEST_URI} style\.css
RewriteRule .* index.php?rt=Asset&%{QUERY_STRING} [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?rt=$1&%{QUERY_STRING} [L]

Options -Indexes # this line is optional
相关问题