Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

I want to redirect http://www.name.com and http://name.com/ to http://my.name.com/.

Examples http://www.name.com/ goes to http://my.name.com http://name.com/ goes to http://my.name.com http://www.name.com/picture.jpg no redirect http://name.com/folder/picture.jpg no redirect

Thanks.

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.

1 Answer 1

up vote 2 down vote accepted

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

RewriteRule ^/$ http://my.name.com/ [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 ^$ http://my.name.com/ [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 ^$ http://my.name.com/ [R=301,L]
share|improve this answer
    
Doesn't this redirect everything to my.name.com? I'm looking to only redirect when the URL is exactly name.com or name.com –  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 http://name.com/ 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.