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

All of the names currently point to the same web server folder which is correct. That is, the,, etc all work without redirecting to the main .com

How do I get visits to the .org and .net to redirect the browser to

This should be basic, but I am can't figure out the best approach.

share|improve this question
up vote 3 down vote accepted

I would suggest you to use RewriteRule from mod_rewrite than use Redirect from mod_alias. As mod rewrite is more versatile.

<VirtualHost *:80>
     ServerAlias www.
     RewriteEngine on
     RewriteCond %{HTTP_HOST} ^(www\.)?domain\.(net|org)$ [NC]
     RewriteRule ^{REQUEST_URI} [L,R=301]

<VirtualHost *:80>
    DocumentRoot /path/to/documentroot
    ErrorLog logs/
    CustomLog logs/ common

Make sure you have NameVirtualHost *:80 uncommented.


     RewriteEngine on

Sets the RewriteEngine on

     RewriteCond %{HTTP_HOST} ^(www\.)?domain\.(net|org)$ [NC]

Matches %{HTTP_HOST}: i.e: The base URL of the host. For more on RewriteCond & http headers visit: RewriteCond. [NC] is a flag: 'nocase|NC' (no case)

This makes the test case-insensitive - differences between 'A-Z' and 'a-z' are ignored, both in the expanded TestString and the CondPattern. This flag is effective only for comparisons between TestString and CondPattern. It has no effect on filesystem and subrequest checks.

Also you have to redirect URL's that start with WWW as well. that is why ^(www\.) in the pattern.

     RewriteRule ^{REQUEST_URI} [L,R=301]

Rewrites the URL to if a match in RewriteCond Occurs. Adds any request URI if present. i.e. The URI for this request (relative to DOCUMENT_ROOT).

if URl was: then REQUEST_URI=/web/hello.php

share|improve this answer
This is a good solution if your redirects are tricky or conditional, but if you just need to change hostnames whilst preserving paths the Redirect solution is simpler IMO (and more readable). – nickgrim Jan 19 '12 at 11:44
@nickgrim I agree its simpler. I am trying to take care of most cases here. – ThinkingMonkey Jan 19 '12 at 12:56


What I do in this particular situation is to create a separate virtualhost block

<VirtualHost *>

   Redirect permanent

Hope that helps.

Ismael Casimpan

share|improve this answer
Thanks, is there a difference between ServerName, ServerAlias? – Pasta Jan 19 '12 at 11:21
With that solution, a request to say will just be redirected to without the rest of the URI. That's not too bright if people have bookmarked deeplinks to the .org or .net hosts for example – Mathias R. Jessen Jan 19 '12 at 11:30
@Pasta You can only have one ServerName, and it's intended to be canonical. You can have as many ServerAliases as you like. Docs are here. – nickgrim Jan 19 '12 at 11:38
@JudasIscariot1651 That's completely not true; the documentation for Redirect states "Additional path information beyond the matched URL-Path will be appended to the target URL". – nickgrim Jan 19 '12 at 11:41
@nickgrim I apologize for my ignorance, I seldom use mod_alias, always mod_rewrite – Mathias R. Jessen Jan 19 '12 at 13:07

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.