Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

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


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