.htaccess - Google 搜索结果中的链接未按照 .htaccess 重定向到预期页面

标签 .htaccess redirect

我最初问了一个.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/

相关文章:

php - AuthUserFile 没有在配置错误中指定?

javascript - 替换部分 URL onclick 并重定向

php - 在 htaccess 上使用 header() 找不到 404

apache - 如何限制特定 IP 范围查看 .htaccess 中的特定页面?

magento - 本地暂存 magento 站点重定向到实时站点

php - 自定义模板的 WordPress URL 重写

regex - .htaccess 重定向和可见 URL

javascript - SWFObject redirectUrl 不适用于 ExpressInstall

JSF "faces-redirect=true"从 https ://to http://URL due to Apache ProxyPass 重定向

php - 如何重定向到 PHP 中的感谢页面