Apache Redirect 301 Problem.

Discussion in 'Site & Server Administration' started by Blaster, Oct 4, 2007.

  1. #1
    Can someone please provide me a little assistance? I’m trying to do a 301 redirect so that when a user enters http://test.com they will be redirected to http://www.test.com . Below are my current httpd configurations. I’m also running two websites on one IP. I’ve tried a lot of things and would love to avoid having to make modifications to the .htaccess file.

    Current Configuration

    NameVirtualHost *:80
    <VirtualHost *:80>
    ServerName www.test.com
    ServerAlias www.test.com test.com
    DocumentRoot /srv/www/htdocs/test
    CustomLog /var/log/apache2/test/access_log combined
    ErrorLog /var/log/apache2/test/error_log
    </VirtualHost>

    <VirtualHost *:80>
    ServerName www.test2.com
    ServerAlias www.test2.com test2.com
    DocumentRoot /srv/www/htdocs
    CustomLog /var/log/apache2/test2/access_log combined
    ErrorLog /var/log/apache2/test2/error_log
    </VirtualHost>

    I’ve also tried the following which didn’t seem to work.

    NameVirtualHost *:80
    <VirtualHost xx.xx.xx.xx> ServerName test.com
    RewriteEngine on
    RewriteRule ^/(.*) http://www.test.com/$1 [L,R=301]
    DocumentRoot /srv/www/htdocs/test
    CustomLog /var/log/apache2/test/access_log combined
    ErrorLog /var/log/apache2/test/error_log
    </VirtualHost>

    <VirtualHost *:80> ServerName test2.com
    RewriteEngine on
    RewriteRule ^/(.*) http://www.test2.com/$1 [L,R=301]
    DocumentRoot /srv/www/htdocs
    CustomLog /var/log/apache2/test2/access_log combined
    ErrorLog /var/log/apache2/test2/error_log
    </VirtualHost>
     
    Blaster, Oct 4, 2007 IP