【问题标题】:using mod_rewrite to get rid of question mark使用 mod_rewrite 去掉问号
【发布时间】:2012-01-16 23:28:22
【问题描述】:

好吧...所以我有这个 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]

不用说,它没有用。

【问题讨论】:

  • 看来问题出在 b 值中的斜线

标签: php apache .htaccess mod-rewrite redirect


【解决方案1】:

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

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

但是,根据您的示例 URL,您似乎想要更多这样的东西:

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

【讨论】:

    【解决方案2】:

    如果您想从查询字符串中删除?,但又想保留与号,即&,这看起来是一件不寻常的事情。

    无论如何,如果这是您真正想要的,那么您可以将此代码放入您的 .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

    【讨论】:

    • 问题是我的缓存不会存储带有“?”的文件。在他们的网址中。我将如何删除&符号?
    • 哦,那么您希望最终的 URI 是什么?
    • 我不确定什么是传统的
    • 好的,检查我更新的答案,看看这是否适合你。
    • 嗯...我刚刚进入我的 404 页面
    猜你喜欢
    • 2020-12-13
    • 1970-01-01
    • 2018-02-28
    • 2016-06-14
    • 2013-12-04
    • 1970-01-01
    • 1970-01-01
    • 2013-07-06
    • 2023-03-06
    相关资源
    最近更新 更多