Server Fault is a question and answer site for system and network administrators. 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

Possible Duplicate:
Everything You Ever Wanted to Know about Mod_Rewrite Rules but Were Afraid to Ask?

I want to redirect and to

Examples goes to goes to no redirect no redirect


share|improve this question

marked as duplicate by mgorven, rnxrx, EEAA, Ward, John Gardeniers Oct 26 '12 at 8:58

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

up vote 2 down vote accepted

Some more information about your setup would be good, but essentially:

RewriteRule ^/$ [R=301,L]

That's for in your virtual host configs for the domains that are redirecting; if it's in an htaccess or <Directory> block then you'll need to remove path information:

RewriteRule ^$ [R=301,L]

..and if it's in a location like an htaccess that applies to all of the domain names, then you'll need to have it not redirect for the target domain.

RewriteCond %{HTTP_HOST} !^my\.name\.com$ [NC]
RewriteRule ^$ [R=301,L]
share|improve this answer
Doesn't this redirect everything to I'm looking to only redirect when the URL is exactly or – Michael Oct 25 '12 at 1:23
@Michael Nope! My match string in the first one is ^/$ - it must be an exact match, with the start and end of the string directing preceding and following the slash. Within a <Directory> or .htaccess context, the directory path is stripped, so a request for comes in to mod_rewrite's match process as an empty string, which is exactly what ^$ will match in the second and third examples. – Shane Madden Oct 25 '12 at 1:27
thank you very much – Michael Oct 25 '12 at 17:16

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