Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I am trying to redirect www.domain.com or domain.com to www.domain.com/temp.html

I am using the following code:

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^/?$ "http\:\/\/www\.domain\.com\/temp\.html" [R=301,L]

That works however I do not want to redirect IP. So if someone types in the static IP of the domain then I do not want them to be redirected to www.domain.com/temp.html

Anyone have the code to take care of this?

share|improve this question

migrated from stackoverflow.com Oct 21 '12 at 4:17

This question came from our site for professional and enthusiast programmers.

2 Answers 2

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

don't usethe ^.*$, that matches all, plus you can end up with a redirect loop

share|improve this answer

You can make that exclusion by changing your HTTP_HOST condition:

RewriteCond %{HTTP_HOST} !^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$
RewriteRule ^/?$ "http\:\/\/www\.domain\.com\/temp\.html" [R=301,L]

or the other way around:

RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^/?$ "http\:\/\/www\.domain\.com\/temp\.html" [R=301,L]
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.