Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

VirtualHost config as below.

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

vhost_alias_module is not loaded.

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

share|improve this question

2 Answers 2

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/
<VirtualHost>

... rest of config

share|improve this answer
    
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

HI,

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] 
share|improve this answer
    
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

 
discard

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.