【问题标题】:Rewrite Rule to append重写规则以追加
【发布时间】:2016-02-28 19:57:41
【问题描述】:

我目前正在研究重写规则,我需要将某些文本附加到重定向的 URL。

我想在浏览器中输入的网址是

http://testwebsite.com/search/?q=SEARCH_STRING

我希望这个重定向到

http://testwebsite.com/search/SEARCH_STRING/

基本上 SEARCH_STRING 需要从 ?= 前面取出并放在 /search/ 之后

我的当前规则出现故障:

RewriteRule ^.*\/search\/\?q=(.*) /#!/search/$1/ [R=301,L,NC,NE]

知道如何解决这个问题吗?

【问题讨论】:

  • 无需在 apache 正则表达式中转义正斜杠。

标签: regex apache mod-rewrite url-rewriting url-rewrite-module


【解决方案1】:

您需要在 RewriteCond 中捕获查询字符串,它不是您的 RewriteRule 隐式匹配的字符串的一部分

RewriteCond %{QUERY_STRING} ^q=(.+)
RewriteRule ^/search/$ /search/%1? [R=301,L,NC,NE]

尾随 ?删除现有的查询字符串。

【讨论】:

    猜你喜欢
    • 2015-09-14
    • 1970-01-01
    • 2016-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-10
    • 1970-01-01
    相关资源
    最近更新 更多