.htaccess 301 将旧域上的所有页面重定向到新域上的单个页面
我希望将旧域上的每个页面重定向到新域上的单个页面.它还应该重定向 www 和非 www 版本.对域 old.com 的每个请求,无论是什么,都应该指向 www.new.com 根.
I'm looking to redirect each and every page on the old domain to a single page on the new domain. It should also redirect both the www and non-www versions. Every single request to the domain old.com, whatever it may be, should lead to www.new.com root.
old.com/1.php
www.old.com/2.php
old.com/2.php
old.com/links/index.php
old.com/about-us.html
old.com/?string=1
应该全部重定向到:
www.new.com/
www.new.com/
我正在寻找 .htaccess 解决方案.
I'm looking for a .htaccess solution.
可以在old.com vhost中使用RedirectMatch
You can use RedirectMatch in the old.com vhost
RedirectMatch permanent .* http://www.new.com/
Redirect
将匹配 URI 的尾随部分附加到重定向 URI,但使用 RedirectMatch
由您选择要传输的部分(如果有)使用括号和 $number
引用.
Redirect
appends the trailing portion of the matched URI to the redirection URI but with RedirectMatch
it's up to you to choose the parts (if any) that you want to transfer using parentheses and $number
references.
如果旧域和新域必须是磁盘上相同文档根目录的别名,那么您可能必须使用 mod_rewrite
If the old and new domains must be aliases for the same document root on disk then you'll probably have to use mod_rewrite
RewriteEngine on
RewriteCond %{HTTP_HOST} old\.com$
RewriteRule .* http://www.new.com/ [L,R=301]