正在替换%252520的标志

时间:2010-09-01 12:06:08

标签: regex .htaccess redirect url-encoding

当我点击Google中的索引页面时,我的查询字符串中的加号正在替换(编码?)%252520。

任何人都知道为什么?

示例:

lovelakedistrict.com/result/?q=Private%252520car%252520park&page=2

应该是

lovelakedistrict.com/result/?q=Private+car+park&page=2

我听说这是在htaccess中重定向我的网址的结果?

2 个答案:

答案 0 :(得分:3)

如果URI查询中使用了空格,则必须将其替换为%20percent encoding)或+application/x-www-form-urlencoded content type替换表单)。在您的情况下,数据似乎被编码三次(%编码为%25)。

尝试使用这些规则将此类序列替换为+

RewriteCond %{QUERY_STRING} (.*?)%(25)+20(.*?%(25)+20.*)
RewriteRule ^ %{REQUEST_URI}?%1+%3 [N]
RewriteCond %{QUERY_STRING} (.*?)%(25)+20(.*)
RewriteRule ^ %{REQUEST_URI}?%1+%3 [L,R=301]

答案 1 :(得分:2)

实际上%25%字符,%20是空格。所以你的URI似乎被编码了三次

http://www.lovelakedistrict.com/result/?q=Private car park&page=2 =>
http://www.lovelakedistrict.com/result/?q=Private%20car%20park&page=2 =>
http://www.lovelakedistrict.com/result/?q=Private%2520car%2520park&page=2 =>
http://www.lovelakedistrict.com/result/?q=Private%252520car%252520park&page=2

如您所见,%编码为%25 因此,第一次,您获得%20空格,然后获得%25 % %20后跟20,然后再获得{{1}} ,相同的编码。

在向Google提供链接之前,此过程可能存在问题。

相关问题