我正在将旧网站域移动到新域。我将所有页面重定向到新域上的相应页面。旧域的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]
答案 0 :(得分:0)
所以,我终于明白了。
第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]