Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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 want to do this: redirect http://anySubdomain(wildcard)



i tried with this:

  RewriteCond %{HTTP_HOST} ^(.*)\$ [OR]
  RewriteRule ^/?$ "http\:\/\/$1\.mydomain\.com\/page2\.php" [R=301,L]

But it does not work, the rewriteCond part works well, because, ANY subdomain is redirected.

But it reaches: "", what makes me think the problem is in the second line

Can you help me? thanks!

share|improve this question

It should be:

RewriteCond %{HTTP_HOST} ^(.*)\.mydomain\.com$
RewriteRule ^(.*)$ /page2.php [R=301,L]

The RewriteRule only takes the URL-path (the part after the domain name) for the regex input. Sounds like you want every page to redirect to page2.php, which is what this does.

share|improve this answer

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.