简体   繁体   English

htaccess特殊字符RewriteRule尚不可用

[英]htaccess special character RewriteRule not working yet

We have a bunch of URLs that were indexed by Google with special apostrophes (url encoded as '%E2%80%99'). 我们有一堆由Google索引并带有特殊撇号的URL(URL编码为'%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. 我们更正了服务器上的网址,但Google仍指向该网址,我们不想在这里中断任何SEO mojo。 Any thoughts why this won't work? 有什么想法为什么这行不通?

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/

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 更多信息

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM