我遇到过类似的问题,例如 this one ,并在 mod_rewrite tutorials 上找到了类似的说明。我已经确定我需要一些类似的东西RewriteRule ^(.*)<(.*)$ /$1$2 [L,R=301]RewriteRule ^(.*)>(.*)$ /$1$2 [L,R=301]这适用于 http://domain.com/<> ,但不适用于 http://domain.com?a=<>我还添加了以下内容,以尝试从查询字符串中删除这些字符:RewriteCond %{QUERY_STRING} ^(.*)<(.*)$RewriteRule ^(.*)$ /$1?%1%2 [L,R=301]RewriteCond %{QUERY_STRING} ^(.*)>(.*)$RewriteRule ^(.*)$ /$1?%1%2 [L,R=301]这并没有改变任何东西。我也试过在正则表达式中转义 (即 ^(.*)\<(.*)$ )。我试图实现的最终结果是http://domain.com/<whatever> 变成 http://domain.com/whatever ,和http://domain.com/a=<whatever>&b=whatever 变成 http://domain.com/a=whatever&b=whatever 最佳答案 < 被编码为 %3C,> 被浏览器编码为 %3E。所以你的规则是这样的:RewriteCond %{QUERY_STRING} ^(.*?)(?:%3C|%3E)(.*)$RewriteRule ^(.*)$ /$1?%1%2 [L,R=302,NE]这会将 http://domain.com/?a=<whatever>&b=whatever 重定向到 http://domain.com/?a=whatever&b=whatever关于.htaccess - 从 .htaccess 中的查询字符串中删除特殊字符,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26426411/
10-13 00:27