Tried a few different approaches; the best 
was 
http://stackoverflow.com/questions/1100343/apache-redirect-from-non-www-to-www

In an Apache config file, e.g. /etc/httpd/conf.d/default.conf for CentOS 
users --

##
## with www
<VirtualHost *:80>
    ServerName www.something.com
    ... lots of other directives
</VirtualHost>

##
## without www -- redirect to www normalize for Google Analytics etc.
## note needs to be AFTER the with-www option so non-matching requests
## like localhost from APIs and command line tools default to that host.
<VirtualHost *:80>
    ServerName something.com
    Redirect permanent / http://www.something.com/
</VirtualHost>


Main points:
(1)  Simpler than the rewrite approach; if you aren't already using 
mod_rewrite you can leave it disabled.
(2)  If you have valid URLs that start with something other than www.x.com 
and x.com (like localhost) you must put the non-www option after the 
with-www option.  When a server name doesn't match, Apache defaults to the 
first server in configuration order that matches the IP address and port.

Regards

-- 



Reply via email to