LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices



Reply
 
Search this Thread
Old 01-27-2012, 09:21 AM   #1
karnaf
Member
 
Registered: Dec 2005
Distribution: Linux Mint 14 (Cinnamon), Xubuntu 12.04, Ubuntu 10.04
Posts: 49

Rep: Reputation: 15
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
 
Old 01-27-2012, 09:56 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,415

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
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
 
Old 01-27-2012, 12:07 PM   #3
karnaf
Member
 
Registered: Dec 2005
Distribution: Linux Mint 14 (Cinnamon), Xubuntu 12.04, Ubuntu 10.04
Posts: 49

Original Poster
Rep: Reputation: 15
I knew there was something I was missing :-)

Thanks!!!
karnaf
 
  


Reply

Tags
apache, redirect, virtualhost


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Host Names For Apache / Web Server? carlosinfl Linux - Server 1 01-11-2011 06:13 PM
LXer: Linux Magazine names Canonical Ltd as one of the top 20 companies ... LXer Syndicated Linux News 0 01-20-2007 08:33 PM
is there a canonical method to get host IP address? bigearsbilly Linux - Networking 2 10-24-2006 08:57 AM
ICMP host redirect htb Linux - Networking 1 08-12-2006 01:08 AM
Apache Virtual Host Redirect granny Linux - Networking 5 05-22-2003 02:20 PM


All times are GMT -5. The time now is 08:23 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration