我最初问了一个.htaccess问题here并得到了一些很棒的帮助,这很有效。基本上,我正在尝试将页面从旧网站重定向到新网站,并设法使大多数事情正常工作。然而,Google 搜索结果中有几个链接没有正确重定向,我相信这是因为它们都是 www,而新网站重定向到非 www。例如,搜索引擎结果中像这样的链接:
www.example.com/Expertise/ProductTesting
应该去:
example.com/services/product-testing
而是转到:
example.com/services/ProductTesting
由于某种原因,URL 的最后一部分没有改变。这是该行在我的 .htaccess 中的外观:
RedirectMatch 301 ^/Expertise/ProductTesting/?$ /services/product-testing/
如果我手动输入地址并删除 www,它会按应有的方式重定向。
提前致谢!
最佳答案
考虑到您之前的问题,您必须将新规则放在匹配所有内容的规则之前:RedirectMatch 301 ^/Expertise/(.*)$/services/$1
。
此外,您可能需要先清除浏览器的缓存,然后再重试(或使用其他浏览器尝试)。
你的规则应该是这样的
RedirectMatch 301 ^/Expertise/QuantitativeResearch/?$ /services/quantitative-research/
RedirectMatch 301 ^/Expertise/ProductTesting/?$ /services/product-testing/
RedirectMatch 301 ^/Expertise/(.*)$ /services/$1
关于.htaccess - Google 搜索结果中的链接未按照 .htaccess 重定向到预期页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25665943/