htaccess特殊字符RewriteRule还没有工作

时间:2022-08-10 10:51:04

We have a bunch of URLs that were indexed by Google with special apostrophes (url encoded as '%E2%80%99'). We corrected the urls on the server, but Google is still pointing there and we didn't want to interrupt any SEO mojo here. Any thoughts why this won't work?

我们有一堆由Google编制的带有特殊撇号的网址(网址编码为'%E2%80%99')。我们更正了服务器上的网址,但谷歌仍然指向那里,我们不想在这里打断任何SEO mojo。有什么想法为什么这不起作用?

Current rewrite rule in .htaccess file:

.htaccess文件中的当前重写规则:

# remove apostrophes from a string
RewriteRule ^(.*)’(.*)$ /$1$2 [L,R=301]
RewriteRule ^(.*)%E2%80%99(.*)$ /$1$2 [L,R=301]

Example replace this URL:

示例替换此URL:

http://example.com/santa%E2%80%99s-comin-to-town/

with this URL:

使用此网址:

http://example.com/santas-comin-to-town/

2 个解决方案

#1


1  

Try using this:

试试这个:

RewriteRule ^(.*)’(.*)$ /$1$2 [B,L,R=301]
RewriteRule ^(.*)([^\w].+\d)(.*)$ /$1$3 [B,L,R=301]

using the % character can have adverse effects on rewrite rules:

使用%字符可能会对重写规则产生负面影响:

(%..%..%..) or (\%..\%..\%..) 

should also work, although make sure you provide the [B] flag on the end of the rule.

也应该工作,但请确保在规则的末尾提供[B]标志。

more info

#2


0  

Use this rule for using hex code in rewrite rules:

使用此规则在重写规则中使用十六进制代码:

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

#1


1  

Try using this:

试试这个:

RewriteRule ^(.*)’(.*)$ /$1$2 [B,L,R=301]
RewriteRule ^(.*)([^\w].+\d)(.*)$ /$1$3 [B,L,R=301]

using the % character can have adverse effects on rewrite rules:

使用%字符可能会对重写规则产生负面影响:

(%..%..%..) or (\%..\%..\%..) 

should also work, although make sure you provide the [B] flag on the end of the rule.

也应该工作,但请确保在规则的末尾提供[B]标志。

more info

#2


0  

Use this rule for using hex code in rewrite rules:

使用此规则在重写规则中使用十六进制代码:

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