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

When I enter in my domain like this

everything works fine. But when I enter it like this

I get the 'It works!' page. I'm a complete Apache newb so I'm not exactly sure whats going wrong here.

share|improve this question

migrated from Dec 14 '09 at 1:49

This question came from our site for professional and enthusiast programmers.

Traditional solution: in the httpd configuration, find:


and add:


However, this will give you a server that responds with the same content on and It's generally considered preferable (particularly SEO-wise) to have only one canonical hostname. To do that, add a new virtual server for the redirect, instead of the alias.

<VirtualHost *:80>
    Redirect permanent /
share|improve this answer

This has to do with the Apache config as others have stated.

Simply added a ServerAlias to the apache config for your virtualhost will do it for you. I don't think that it is good practice to create another virtualhost have it redirect for you.

It is good SEO practice to direct everything to one or the other, I suggest using this in either you config file or in your .htaccess

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteRule ^(.*)$$1 [R=301,L]
share|improve this answer
Why do you not think it is good practice to have a virtualhost do the redirect? It is simpler and has less performance impact than processing everything with mod_rewrite. – bobince Dec 14 '09 at 3:49
I think it is partly to do with preference, but if you have to manage hundreds of virtualhosts, it can become cumbersome to keep all these 'stub' virtualhost up to date and organized. I think there use to be a problem with apache loading up a lot of virtualhost, not sure if this is a problem with apache still. If you are just hosting one or two sites it isn't too big of a deal. – Ryan Gibbons Dec 14 '09 at 14:34

Check the mod_alias at your apache config file, make sure that the regex is correct for redirection.

share|improve this answer
I don't understand the previous -1, checking if mod_alias is enabled is a good tip. – Seb Apr 22 at 18:55

I had this problem too, and found my solution here.

Basically, after an upgrade, Apache put a symlink in /etc/apache2/sites-available. Deleting everything between and including <VirtualHost *:80> and <VirtualHost> got everything working for me again.

share|improve this answer

Another possible solution is that the default site is catching the traffic. This worked for me - if you don't care about disabling the default site altogether:

a2dissite 000-default
service apache2 reload
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.