【问题标题】:How to 301 redirect all pages to the same pages on new domain如何 301 将所有页面重定向到新域上的相同页面
【发布时间】:2012-05-25 11:24:50
【问题描述】:

我正在将我的网站从 old-domain.com 移动到具有完全相同页面的 new-domain.com,例如,如果 old-domain.com 有 page1.html(即 old-domain.com/page1 .html) 则新域具有相同的页面,即 new-domain.com/page1.html

我在 .htaccess 文件中试过这个:

RewriteEngine on
RewriteRule (.*) http://new-domain.com/$1 [R=301,L] 

但只有当 old-domain.com 会重定向到 new-domain.com,old-domain.com/page1.html 不会重定向到 new-domain.com/page1.html

谢谢!

【问题讨论】:

  • (.*) 不会匹配主机,只会匹配 URL 的其余部分。

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


【解决方案1】:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !newdomain.com$ [NC]
RewriteRule ^(.*)$ http://newdomain.com/$1 [L,R=301]

更多解决方案请看这里:http://enarion.net/web/htaccess/migrate-domains/

【讨论】:

    【解决方案2】:

    在你的 htaccess 中试试这个

    Redirect 301 / http://www.new.com/
    

    这会将您的所有页面从http://old.com/page1 重定向(并映射)到http://new.com/page1

    【讨论】:

    【解决方案3】:

    试试这个:

    RedirectPermanent / http://www.new-domain.com/
    

    【讨论】:

      猜你喜欢
      • 2014-09-23
      • 2013-02-10
      • 1970-01-01
      • 2019-09-07
      • 2011-04-26
      • 1970-01-01
      • 2013-02-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多