我有两个域名,一个是旧的域名,另一个是最新的域名。
使用.htaccess文件将旧域上的所有urls重定向到新域的最佳方法是什么
例如,如果我转到old-domain.com/test,它将重定向到new-domain.com/test,或者如果我转到sub.old-domain.com,它将重定向到sub.new-domain.com
发布于 2013-11-18 04:58:07
您希望使用RewriteCond规则和%{HTTP_HOST}参数在“旧”域上进行匹配,并在需要时重定向到“新”域。如果匹配,则使用RewriteRule创建通配符匹配组以执行301重定向。
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} (www\.)?old-domain\.com [NC]
RewriteRule (.*) http://www.new-domain.com/$1 [R=301,NC,QSA,L]使用http://htaccess.madewithlove.be/进行测试
input url
http://old-domain.com/test
output url
http://www.new-domain.com/test
debugging info
1 RewriteEngine on
2 RewriteBase /
3 RewriteCond %{HTTP_HOST} (www\.)?old-domain\.com [NC]
This condition was met
4 RewriteRule (.*) http://www.new-domain.com/$1 [R=301,NC,QSA,L]
This rule was met, the new url is http://www.new-domain.com/test
The tests are stopped, using a different host will cause a redirecthttps://stackoverflow.com/questions/20035136
复制相似问题