有人错误地链接到我的一些url,导致谷歌网站pipe理员工具中的404错误。
这是一个例子
链接url: http://www.example.com/foo-%E2%80%8Bbar.html : http://www.example.com/foo-%E2%80%8Bbar.html
正确的url: http://www.example.com/foor-bar.html : http://www.example.com/foor-bar.html
我想301将这种不正确链接的任何实例redirect到正确的URL。 我已经尝试了以下,但它产生404错误网站广泛。
Options +FollowSymLinks RewriteEngine on RewriteRule ^foo-(.*)bar\.html$ http://www.example.com/foo-bar\.html? [L,R=301]
任何人都可以让我知道我做错了什么?
那么,对于初学者来说,正则expression式
foo-(.*)bar\.html
也会匹配“foo-bar.html”,这是不好的,并导致重写循环。
你想要这个:
foo-(.+)bar\.html
一般来说,重新编写的应该是:
RewriteRule ^/foo-(.+)bar\.html$ /foo-bar.html? [L,R=301]
我的build议是检查Apache Rewrite日志,通常位于/ var / logs / apache2。 这将告诉你重写的结果是什么,并可能帮助你确定为什么这是为你返回404。
您也可以在日志中发布结果,因为这可能有助于我们确定问题。
RewriteEngine on RewriteRule ^foo-(.*)bar\.html$ /foo-bar.html? [L,R=301]