htaccess: exluce some domain in RewriteCond

2020-03-13 06:14发布

this is my .htaccess code so if the user type just domain.com will be redirected to www.domain.com

RewriteBase /
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]

my problem now is that i have a new domain pointing to the same domain path so even the new domain is redirected "transparently" to domain.com...

how can i exclude some domain name from that rule?

thanks!

1条回答
\"骚年 ilove
2楼-- · 2020-03-13 06:42

You could try making the rewrite generic, so all requests that are not starting with www are redirected, but on the correct/requested domain.

RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [L,R=301]

Or, you can check instead for if the domain starts with domain.com:

RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com [L,R=301]

Hopefully this helps.

查看更多
登录 后发表回答