Apache .htaccess-重定向域名
我有一个域名www.domainA.com我想用以下方式将它重定向到域名bApache .htaccess-重定向域名,apache,.htaccess,mod-rewrite,redirect,Apache,.htaccess,Mod Rewrite,Redirect,我有一个域名www.domainA.com我想用以下方式将它重定向到域名b www.domainA.com->www.domainB.com www.domainA.com/anything->www.domainB.com/rebrand 如何在htaccess中做到这一点,我已经完成了以下代码,但它只重定向到/rebrand/ RewriteCond %{REQUEST_URI} ^\/ RewriteRule ^\/$ http://www.domainB.com/ [L,R=301]
www.domainA.com
->www.domainB.com
www.domainA.com/anything
->www.domainB.com/rebrand
如何在htaccess中做到这一点,我已经完成了以下代码,但它只重定向到/rebrand/
RewriteCond %{REQUEST_URI} ^\/
RewriteRule ^\/$ http://www.domainB.com/ [L,R=301]
RewriteCond %{HTTP_HOST} ^domainA\.com$ [NC]
RewriteRule ^(.*)$ http://www.domainB.com/rebrand/ [L,R=301]
在htaccess文件中通过规则的uri去掉了前导斜杠,因此无法与之匹配。对于第二条规则,它与
/
请求匹配,因为第一条规则没有被应用,并且您的正则表达式匹配任何东西或什么都不匹配,您可以通过将*
更改为+
来解决这一问题:
RewriteCond %{HTTP_HOST} ^domainA\.com$ [NC]
RewriteRule ^/?$ http://www.domainB.com/ [L,R=301]
RewriteCond %{HTTP_HOST} ^domainA\.com$ [NC]
RewriteRule ^(.+)$ http://www.domainB.com/rebrand/ [L,R=301]
通过htaccess重定向有时很棘手,有很多方法可以实现,但有一种简单的方法对我有效
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) [newdomain.com...] [R=301,L]
您可以从以下网站获得更多信息: