I want to 301 redirect from: www.olddomain.com to the root of newdomain.com but I want it to work no matter what the folder path is on the old domain. eg: the following should all redirect to the root of newdomain.com
我想将301重定向从www.olddomain.com重定向到newdomain.com的根目录,但无论旧域上的文件夹路径是什么,我都希望它能够正常工作。例如:以下所有内容都应该重定向到newdomain.com的根目录
www.olddomain.com
olddomain.com
www.olddomain.com/folder/file.php
olddomain.com/folder/file.php
How can I do that with Mod Rewrite in the .htaccess file?
如何在.htaccess文件中使用Mod Rewrite执行此操作?
2 个解决方案
#1
Try this rule:
试试这条规则:
RewriteEngine on
RewriteCond %{HTTP_HOST} (^|\.)old\.example\.com$
RewriteRule ^ http://new.example.com/ [L,R=301]
Where old.example.com
is the old host name and new.example.com
the new.
其中old.example.com是旧主机名,new.example.com是新主机名。
#2
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.newdomain.com/page.html");
exit();
?>
This should also work for you.
这对你也有用。
#1
Try this rule:
试试这条规则:
RewriteEngine on
RewriteCond %{HTTP_HOST} (^|\.)old\.example\.com$
RewriteRule ^ http://new.example.com/ [L,R=301]
Where old.example.com
is the old host name and new.example.com
the new.
其中old.example.com是旧主机名,new.example.com是新主机名。
#2
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.newdomain.com/page.html");
exit();
?>
This should also work for you.
这对你也有用。