【问题标题】:Redirect Old Domain to New Domain Except robots.txt将旧域重定向到新域,除了 robots.txt
【发布时间】:2014-09-27 07:19:52
【问题描述】:

我正在将旧站点域移至新域。我将所有页面重定向到新域上的相应页面。旧域的 robots.txt 文件正在重定向到新域的 robots.txt 文件。我想重定向除 robots.txt 文件之外的所有页面。我该怎么做呢?

我的 .htaccess 文件

# Redirect the site 
RewriteEngine On 

# Take care of www.olddomain.com
 RewriteCond %{HTTP_HOST} ^www.olddomain.com$ [NC] 
 RewriteRule ^/robots\.txt$ /robots.real [L]
 RewriteRule ^(.*)$ http://newdomain.com/$1 [L,R=301] 
# Takes care of olddomain.com 
 RewriteCond %{HTTP_HOST} ^olddomain.com$ [NC] 
 RewriteRule ^/robots\.txt$ /robots.real [L]
 RewriteRule ^(.*)$ http://newdomain.com/$1 [L,R=301]

【问题讨论】:

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


    【解决方案1】:

    所以,我终于想通了。

    第 6 行和第 10 行需要如下所示:

    RewriteCond %{REQUEST_URI} !^/robots.txt$ [NC]
    

    这会导致以下代码:

    # Redirect the site 
    RewriteEngine On 
    
    # Take care of www.olddomain.com
     RewriteCond %{HTTP_HOST} ^www.olddomain.com$ [NC] 
     RewriteCond %{REQUEST_URI} !^/robots.txt$ [NC]
     RewriteRule ^(.*)$ http://newdomain.com/$1 [L,R=301] 
    # Takes care of olddomain.com 
     RewriteCond %{HTTP_HOST} ^olddomain.com$ [NC] 
     RewriteCond %{REQUEST_URI} !^/robots.txt$ [NC]
     RewriteRule ^(.*)$ http://newdomain.com/$1 [L,R=301]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-08
      相关资源
      最近更新 更多