【问题标题】:Redirect all but some to new URL?将除部分之外的所有内容重定向到新 URL?
【发布时间】:2012-02-25 11:46:45
【问题描述】:

我正在移动网站,我想对除部分 URL 之外的所有 URL 进行 301 重定向,

像这样:

oldsite.com/* -> www.newsite.com

oldsite.com/specific/article/to/redirect -> www.newsite.com/fancy/blah

所以我想将一些东西重定向到特定页面,但其余的都应该转到 root,如何在 .htaccess 中完成?

【问题讨论】:

  • 你用的是什么网络服务器?
  • 在新站点上 - nginx,在旧站点上 - apache

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


【解决方案1】:

如果您只有一个 URL 需要豁免,则可以使用 RedirectMatch。

RedirectMatch permanent !/specific/article/to/redirect http://www.newsite.com

对于多个 URL,您最好使用 mod_rewrite 和一个外部 rewritemap 来列出要豁免的 URL。

【讨论】:

    【解决方案2】:

    将以下内容添加到旧站点根目录中的.htaccess 文件中。

    #place your specific redirects first 
    Redirect 301 /specific/article/to/redirect http://www.newsite.com/fancy/blah
    
    RewriteEngine on
    
    #then your general redirect all to new site last
    RewriteRule ^ http://www.newsite.com%{REQUEST_URI} [L,R=301]
    

    【讨论】:

      猜你喜欢
      • 2020-11-27
      • 2021-05-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-05
      • 1970-01-01
      • 2016-02-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多