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 have 3 domain names for one site. e.g,, I want to redirect and to I know this has to do with redirecting, but where do I put the redirect rules? in apache, or .htaccess. Any pointers? Currently I have this set up as 3 different virtual hosts pointing to the same folder. Thank you.

share|improve this question
You can put the redirect rules in several places, including Apache's configuration and .htaccess files. – Chris S Mar 23 '11 at 19:45
thanks for the link Chris – berto77 Mar 23 '11 at 21:08

You can do this with either .htaccess or by add Rewrite rules in the VirtualHost config directly. The apache docs here would tell you not to use .htaccess if you can edit the server config. If you do this in .htaccess when you don't need to, apache has to first check if this file exists for every page hit.

For the redirect itself, you could use something like Redirect 301 / if you want to redirect to ; if you want it to actually redirect to (retaining the rest of the url after the hostname), you can instead use RedirectMatch 301 ^(.*)$$1 The docs for Redirect and RedirectMatch are here

share|improve this answer
RewriteCond %{HTTP_HOST} ^(| [NC] RewriteRule ^(.*)$ http: //$1 [R=301,L] ...I tried this but it didn't work. I placed that in the virtual host definition of the – berto77 Mar 23 '11 at 20:47
yes, that achieves the same thing with mod_rewrite instead of mod_alias (in a way that I think is less readable :) ) And you'd better add "RewriteEngine on" to the beninning of that – stew Mar 23 '11 at 20:49
Where do you put the redirect rule? I have access to apache config file. Right now I have it in the <Directory></Directory> tags of – berto77 Mar 23 '11 at 20:51
In the <VirtualHost> section, not inside any subsection. since you are going to redirect all traffic from this VirtualHost, any <Directory> or <Location> or <Files> like subsections are going to be irrelevant anyway – stew Mar 23 '11 at 20:53
Of the example2 and 3? or example1? – berto77 Mar 23 '11 at 20:57

You can do this with DNS. In your external DNS records point and to the external IP of

share|improve this answer
This doesn't "redirect", it just shows the example1 site with the other addresses. – Chris S Mar 23 '11 at 19:44
so I need to set up DNS records for and I'm hosting with slicehost – berto77 Mar 23 '11 at 19:45
True, it doesn't "redirect", however, it does depend on the desired result. If the desired result is to have & as aliases for then this works. – HostBits Mar 23 '11 at 19:51

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.