【问题标题】:301 redirect with exceptions not working301 重定向异常不工作
【发布时间】:2012-11-14 03:25:59
【问题描述】:

我现在真的被困住了,所以很感激任何帮助。

我正在尝试将站点重定向到另一个域,但有一些例外。这是我现在在 .htaccess 文件中的代码

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !/sitemap/
RewriteCond %{REQUEST_URI} !/contact-us/
RewriteRule ^.*$ http://www.newsite.com/folder/$0 [R=301,L]

Redirect 301 /sitemap/ http://www.newsite.com/sitemap/
Redirect 301 /contact-us/ http://www.newsite.com/contact-us/

任何想法为什么这可能不起作用?

主页和站点地图以及联系我们页面重定向正常,但所有其他页面未重定向。

提前致谢。

【问题讨论】:

    标签: .htaccess redirect http-status-code-301


    【解决方案1】:

    将重定向行上移

    RewriteEngine On
    Redirect 301 /sitemap/ http://www.newsite.com/sitemap/
    Redirect 301 /contact-us/ http://www.newsite.com/contact-us/
    RewriteBase /
    RewriteCond %{REQUEST_URI} !/sitemap/
    RewriteCond %{REQUEST_URI} !/contact-us/
    RewriteRule ^.*$ http://www.newsite.com/folder/$0 [R=301,L]
    

    我在我的 apache 服务器上试过了,它成功了

    http://www.oldsite.com/sitemap/ => http://www.newsite.com/sitemap/
    http://www.oldsite.com/contact-us/ => http://www.newsite.com/contact-us/
    http://www.oldsite.com/test => http://www.newsite.com/folder/test
    

    【讨论】:

      猜你喜欢
      • 2014-08-11
      • 2021-02-08
      • 2015-08-09
      • 1970-01-01
      • 2013-09-20
      • 2013-02-06
      • 2023-03-13
      • 2013-05-16
      相关资源
      最近更新 更多