【问题标题】:How can I use htaccess rewrite to remove square brackets from a query string?如何使用 htaccess rewrite 从查询字符串中删除方括号?
【发布时间】:2020-05-12 16:18:09
【问题描述】:

只是无法让它工作。

试图得到这个:

www.myexample.com/querypage.php?query=[blabla]

重定向到这个:

www.myexample.com/querypage.php?query=blabla

当它不在这样的查询字符串中时,我可以让它工作:

RewriteRule ^(.*)\[(.*)\] /$1$2 [R=301,L,NC]

但是查询字符串让我无法理解。

【问题讨论】:

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


    【解决方案1】:

    您可以将RewriteCond%{QUERY_STRING} 一起使用:

    RewriteEngine On
    
    RewriteCond %{QUERY_STRING} ^(query)=\[(blabla)\]$
    RewriteRule ^(querypage\.php)$ /$1?%1=%2 [L,R=301,NC]
    

    【讨论】:

    • 很高兴知道,您能否通过单击我的答案左上角的勾号将答案标记为已接受。
    猜你喜欢
    • 1970-01-01
    • 2021-11-02
    • 1970-01-01
    • 1970-01-01
    • 2021-08-18
    • 1970-01-01
    • 2023-04-10
    • 2016-10-05
    相关资源
    最近更新 更多