我遇到过类似的问题,例如this one,并在mod_rewrite tutorials上找到类似的说明。在.htaccess中删除查询字符串中的特殊字符
我已经决定,我需要沿着
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]
这没有ch任何东西。我也尝试在正则表达式中尝试转义<和>(即^(.*)\<(.*)$
)。
,我试图达到的最终结果是有
http://domain.com/<whatever>
转成http://domain.com/whatever
,并
http://domain.com/a=<whatever>&b=whatever
转成http://domain.com/a=whatever&b=whatever
我敢发誓该编码发生_after_的的.htaccess被考虑在内。很高兴知道这不是在RewriteCond上的情况(或者它只是与查询字符串?) – jperezov 2014-10-17 15:04:48
是的,我相信它只是与查询字符串的情况下。 – anubhava 2014-10-17 15:06:59
完美答案!今天学到了关于查询字符串编码时序的新内容。谢谢! – Concept211 2017-06-22 09:55:16