LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (http://www.linuxquestions.org/questions/linux-server-73/)
-   -   Apache Redirect for canonical host names (http://www.linuxquestions.org/questions/linux-server-73/apache-redirect-for-canonical-host-names-925976/)

karnaf 01-27-2012 08:21 AM

Apache Redirect for canonical host names
 
Hi all,

I am trying to set a redirect rule in my Apache config so that any request coming to http://example.com will be permanently redirected to http://www.example.com

However, when I follow these instructions:
http://httpd.apache.org/docs/2.3/rew...#canonicalhost
http://wiki.apache.org/httpd/CanonicalHostNames

I get a warning when restarting httpd
Code:

[warn] _default_ VirtualHost overlap on port 80, the first has precedence
and when trying to access http://example.com or http://www.example.com I get - Error 310 There were too many redirects.

Any suggestions? what am I missing?
(BTW, I'm trying to avoid using mod_rewrite for this if possible)


Here are the relevant httpd.conf settings
Code:

ServerName www.example.com
UseCanonicalName Off


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

<VirtualHost *:80>
        ServerName www.example.com
        ServerAlias sub1.example.com
        ServerAlias sub2.example.com
        ServerAlias sub3.example.com
        ServerAlias sub4.example.com

        DocumentRoot /somewhere/over/the/rainbow

        SetEnv FOO "bar"

        FileETag All

        ExpiresActive On
        ExpiresByType text/css "access plus 1 week"
        ExpiresByType text/javascript "access plus 1 week"

        <Directory "/somewhere/over/the/rainbow">
                Options FollowSymlinks
                AllowOverride All
                Order allow,deny
                Allow From all
        </Directory>

</VirtualHost>

Thanks,
karnaf

acid_kewpie 01-27-2012 08:56 AM

You've not enabled "NameVirtualHost *:80" in httpd.conf, so it's not paying any attention to the ServerName / ServerAlias variables, so always hitting the first host

karnaf 01-27-2012 11:07 AM

I knew there was something I was missing :-)

Thanks!!!
karnaf


All times are GMT -5. The time now is 01:03 AM.