开发者

htaccess: exluce some domain in RewriteCond

开发者 https://www.devze.com 2023-02-25 02:49 出处:网络
this is my .htaccess code so if the user type just domain.com will be redirected to www.domain.com 开发者_如何学PythonRewriteBase /

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

开发者_如何学PythonRewriteBase /
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!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消