Super User is a question and answer site for computer enthusiasts and power users. 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

Like many users, we tend to register the *.com and *.net versions of our domain names to prevent nefarious squatters. So if we wanted "" we'd also register "" and have them both resolve to the same IP address.

I'm trying to set up Apache for the first time and need to know the proper way to redirect requests to "" to go to "" instead so that if a user types in "" they get magically redirected to "".

I've been reading through the Apache URL Rewriting guide and it's not readily apparent how to do this seemingly simple task.

share|improve this question
superuser is for computer software and hardware. This question is not within that scope. I suggest serverfault. – Josh K Mar 22 '10 at 17:08
up vote 6 down vote accepted

You don't need to rewrite this.. just add another vhost that points to the same DocumentRoot, e.g.:

<VirtualHost *:80>
        DocumentRoot "/var/www/"

<VirtualHost *:80>
        DocumentRoot "/var/www/"

If you're unfamiliar with vhosts, you might want to read about them here.


In response to OP's comment:

I understand what you want now. What you're looking for is a ServerAlias redirect. So, in your vhost, you can add something like:

<VirtualHost *:80> 
    redirect permanent /
share|improve this answer
Thx for the reply. My weak understanding leads me to believe that the user would still be looking at "" in their browser (even though looking at the same files as "") and that the logs would reflect that if I did this. I'd like to redirect the user to "" if possible so that their bookmarks and our logs always reflect a visit to "" – cpuguru Mar 22 '10 at 17:07
@cpuguru see my edit above – Matt Mar 22 '10 at 17:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .