How do I force all "non-WWW" url requests to my "www" domain? · Blog

This is quite simple to do in Apache with your .htaccess file (if you don't have a .htaccess file in your web root, you can add one).

The following is what I use on my site to accomplish this:
Code
# Allow Re-Writing
RewriteEngine on

# Redirect non-www URLs to WWW
RewriteCond %{HTTP_HOST} ^site.tld$
RewriteRule ^(.*) http://www.site.tld/$1 [QSA,L,R=301]


Simply replace "site.tld" with your domain on the two lines that it's mentioned, insert into your .htaccess file, and upload to your server.

Due to the non-www stance some users use, I'm also going to describe how to send all www requests to the non-www domain... Be sure that you're not using both of these as you could cause a lot of looping on your webserver.

The instructions above are still valid, however, use this .htaccess block.

Code
# Allow Re-Writing
RewriteEngine on

# Redirect WWW URLs to non-www
RewriteCond %{HTTP_HOST} ^www.site.tld$
RewriteRule ^(.*) http://site.tld/$1 [QSA,L,R=301]

Posted By Gremelin Posted on June 23, 2007

Comments

( Posted)
Request a Quote
Please feel free to Request a Quote at any time.

By requesting a quote you allow us to adjust pricing for your product on a per-project basis. Note that most of the prices on our pricing page are just our "common" pricing and can vary on a per project basis. It will also allow us to add any per project discounts where we see fit (non-profit organizations, affiliations, etc).

If your "type" of project isn't listed in our menu's to the left, please Request a Quote; we can do much more than what is listed however building pages for it all would take a great while.
Hosting
We utilize BlueHost and StableHost for the hosting of our all of our Virtual Private Servers, the go to hosts that we recommend to every one of our clients, friends, and family. For more Web Hosting recommendations, please see our Recommended Hosts page!

StableHost Web Hosting
Buy Us a Coffee