Reputation: 2742
I have 2 different domains on the same server: domain1.com and domain2.com on server address 100.12.12.222 and simple redirection rule for non-www to www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
and I'd like to have a rule like: if host=domain1.com then redirect to www.domain1.com and if host=100.12.12.222 don't redirect to www.domain1.com
I tried to add:
RewriteCond %{REMOTE_ADDR} ^100\.12\.12\.222
RewriteRule (.*) http://100.12.12.222/$1 [R=301,L]
which works if the second domain doesn't have non-www to www redirection
so I googled and read apache advices and tried to combine something like:
RewriteCond %{HTTP_HOST} !^www\. [OR]
RewriteCond %{REMOTE_ADDR} !^100\.12\.12\.222
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
here I tried to use HTTP_HOST and various things, but it doesn't redirect right. Your help would be very appreciated.
Upvotes: 0
Views: 4013
Reputation: 10898
Drop the [or] flag. You want to redirect to www. if the host is not www...
and the remote != 100.12.12.222
Upvotes: 1