使用mod_rewrite摆脱问号

时间:2012-01-12 11:41:08

标签: php apache .htaccess mod-rewrite redirect

好吧......所以我有这个css捆绑器,使用以下链接:

http://www.example.com/min/?b=wp-content/themes/mytheme&f=style.css,boxes.css,mods.css,scripts.css

参数b是css文件夹url,参数f是要获取的css文件。

然而,为了帮助我的缓存,我希望问号消失了。如果可能的话,比如:

http://www.example.com/min/b=wp-content/themes/mytheme&f=style.css,boxes.css,mods.css,scripts.css

我尝试了以下内容:

RewriteEngine On
RewriteRule ^/([^/\.]+)/?$ index.php?b=$1 [L]

毋庸置疑,它没有用。

2 个答案:

答案 0 :(得分:0)

您的规则将循环播放,您可以尝试在规则前添加条件,使其看起来像这样:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule ^/([^/\.]+)/?$ index.php?b=$1 [L]

但似乎根据您的示例网址,您需要更像这样的内容:

RewriteRule ^min/b=(.*)$ index.php?b=$1 [L]

答案 1 :(得分:0)

在您想要从查询字符串中删除?但希望保留&符号&时,这似乎是一件不寻常的事情。

无论如何,如果这是你真正想要的,那么你可以把这个代码放在.htaccess中:

Options +FollowSymLinks -MultiViews
RewriteEngine on

RewriteRule ^min/b=([^;]*);f=(.*)$ min/?b=$1&f=$2 [L]

此规则会在内部将http://www.example.com/min/b=wp-content/themes/mytheme;f=style.css,boxes.css,mods.css,scripts.css重定向到http://www.example.com/min/?b=wp-content/themes/mytheme&f=style.css,boxes.css,mods.css,scripts.css

相关问题