如何使用htaccess重写从查询字符串中删除方括号?

时间:2014-03-15 04:45:03

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

无法让这个工作。

试图得到这个:

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

重定向到此:

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

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

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

但查询字符串让我不知所措。

1 个答案:

答案 0 :(得分:1)

您可以将RewriteCond%{QUERY_STRING}

一起使用
RewriteEngine On

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