httpd Redirect / Rewrite .com to .org

Posted by David W on Server Fault See other posts from Server Fault or by David W
Published on 2012-10-03T00:20:44Z Indexed on 2012/10/15 3:42 UTC
Read the original article Hit count: 434

Filed under:
|

I am trying to redirect a www.example.com to www.example.org. I cannot figure out what I'm doing wrong.

I have ensured that mod_rewrite is enabled in httpd.conf with:

LoadModule rewrite_module modules/mod_rewrite.so

I further verify this by running: httpd -M and getting rewrite_module (shared) included in the results.

Later in the same httpd.conf file is the VirtualHost directive where I am trying to perform the rewrite:

<VirtualHost *:80>
    Options +FollowSymlinks
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^example.com [NC]
    RewriteRule ^(.*)$ http://www.example.org/$1 [R=301,NC,L]

    ServerAdmin [email protected]
    DocumentRoot /var/www/html
    ServerName example.org
    ServerAlias www.example.org *.example.org
        <Directory "/var/www/html">
                Options Includes FollowSymLinks
                AllowOverride All
                Order allow,deny
                Allow from all
        </Directory>
    ErrorLog /var/www/logs/error_log
    CustomLog /var/www/logs/access_log common
</VirtualHost>

As we can see, we are following SymLinks in the directory (which I believe is a requirement), AND we allow All Overrides (which meets another requirement). But obviously I'm still doing something wrong.

Can you spot it?

© Server Fault or respective owner

Related posts about mod-rewrite

Related posts about httpd