这已经得到了回答,但这里的代码完全包含有用的注释,因此人们可以参考,以便他们以后忘记它的作用。
把它放在你的 .htaccess 文件中:
## Each and every page on old domain redirects to single page
## By appending question mark to new domain, query strings are removed
RewriteEngine on
RewriteCond %{HTTP_HOST} old\.com$
RewriteRule .* http://www.new.com/? [L,R=301]
您还可以重定向到另一个域上的子目录,就像我需要这样做的情况一样:
## Each and every page on old domain redirects to single page
## By appending question mark to new domain, query strings are removed
RewriteEngine on
RewriteCond %{HTTP_HOST} old\.com$
RewriteRule .* http://www.new.com/sub-directory/? [L,R=301]