Was this page helpful?

Redirecting canonical hostnames in Apache (301 redirection)

    Table of contents
    No headers

    In this example "domain.com" is redirected to "www.domain.com" with a 301 http response.

    Open your deki configuration file. (Generally it is located at "/etc/apache2/sites-available/deki" on linux servers.)

    nano /etc/apache2/sites-available/deki

    It should look like this:

    <VirtualHost *>
    	ServerName www.domain.com
    
    	ErrorLog /var/log/apache2/error.log 
    	CustomLog /var/log/apache2/access.log common
    
    	DocumentRoot "/var/www/domain"
    
    	RewriteEngine On
          ...
    </VirtualHost>
    

    Add "NameVirtualHost *" line on top of the file.

    NameVirtualHost *
    
    <VirtualHost *>
    	ServerName www.domain.com

    Add these lines to the end of the file:

    <VirtualHost *>
    	ServerName domain.com
    	RedirectMatch 301 ^/(.*) http://www.domain.com/$1
    </VirtualHost>
    

    Finally your deki configuration file should look like this:

    NameVirtualHost *
    
    <VirtualHost *>
    	ServerName www.domain.com
    
    	ErrorLog /var/log/apache2/error.log 
    	CustomLog /var/log/apache2/access.log common
    
    	DocumentRoot "/var/www/domain"
    
    	RewriteEngine On
          ...
    </VirtualHost>
    
    <VirtualHost *>
    	ServerName domain.com
    	RedirectMatch 301 ^/(.*) http://www.domain.com/$1
    </VirtualHost>
    
    Was this page helpful?
    Tag page
    You must login to post a comment.

    Copyright © 2011 MindTouch, Inc. Powered by