VirtualHost config as below.

<VirtualHost *:80>
ServerName www.domain.com
ServerAlias domain.com
DocumentRoot "/opt/lampp/htdocs/site"
ErrorDocument 404 /

vhost_alias_module is not loaded.

What I want is redirecting domain.com to www.domain.com instead of the opposite.


This is how we do this - using a "Redirect permanent" at the top of the vhost-config:

<VirtualHost *:80>
    ServerName domain.com
    Redirect permanent / http://www.domain.com/

... rest of config

  • I tried this. It gave a circular redirect – powerboy May 1 '11 at 10:28
  • "I think there is already a redirect rule set somewhere else. But I don't where is!!" What webapp software is running on your site? E.g Drupal or WordPress? And are these running any plugins that redirect? Or do these create .htaccess files in the webroot? – Henk May 1 '11 at 10:43
  • Where else can we set redirect rules, other than VirtualHost config and .htaccess? – powerboy May 1 '11 at 10:45
  • Take a look at this answer too: stackoverflow.com/questions/5162625/… – Henk May 1 '11 at 10:50


Create a .htaccess file under the document root of the domain and insert the following code to it.

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{http_host} ^domain.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L] 
  • Same thing. It gives me a circular redirect!! – powerboy May 1 '11 at 10:32
  • Firefox has detected that the server is redirecting the request for this address in a way that will never complete. – powerboy May 1 '11 at 10:32
  • I think there is already a redirect rule set somewhere else. But I don't where is!! – powerboy May 1 '11 at 10:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.