将旧域停放到htaccess后面的新网站(域):
RewriteCond %{HTTP_HOST} ^(www.)?mynewsite.com$
RewriteRule ^(/)?$ mynewsite.com/index.php [L]
RewriteCond %{HTTP_HOST} ^old\-site\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.old\-site\.com$
RewriteRule ^/?$ "http\:\/\/mynewsite\.com" [R=301,L]
人们会喜欢的旧链接: old-site.com/support.php,old-site.com/en/index.php,old-site.com/en/support.php,old-site.com/msg/text.php 当我点击它时出现错误ERROR 404。
如何将它们重定向到新域上的相同地址? old-site.com/support.php - > mynewsite.com/support.php,old-site.com/en/index.php - > mynewsite.com/en/index.php
答案 0 :(得分:1)
如果旧网站作为单独的域(不同的vhost)托管,则在旧网站.htaccess
中<:p>
RewriteCond %{HTTP_HOST} old\-site\.com$
RewriteRule ^(.*)$ http://mynewsite.com [R=301,L]
然后在新网站.htaccess
:
RewriteCond %{HTTP_HOST} ^www.mynewsite.com$
RewriteRule ^(.*)$ http://mynewsite.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.* http://%{HTTP_HOST}/? [R=301,L]
如果他们都在同一个虚拟主机中(旧域名是别名),那么您可以这样做:
RewriteCond %{HTTP_HOST} old\-site\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.mynewsite.com$
RewriteRule ^(.*)$ http://mynewsite.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.* http://%{HTTP_HOST}/? [R=301,L]