Add www. to your domain automatically with htaccess

 

Looking for an easy way to make sure that visitors always see www.yourdomain.com instead of yourdomain.com? It’s simple if you’re hosting on a server that can handle .htaccess files. Take a look at the code below:

RewriteEngine on
Options FollowSymlinks
rewritecond %{http_host} ^ageedesign.com [nc]
rewriterule ^(.*)$ http://www.ageedesign.com/$1 [r=301,nc]
 

Using this code anytime a visitor visits any page on your website, the URL will be automatically updated to include the www. Simply copy/paste this code into a file called .htaccess and save it at the root level of your website and upload it and you should be in business! For more information on htaccess and MOD Rewrite check out this article.

2 Responses to “Add www. to your domain automatically with htaccess”

  1. This does not seem to be working. I tried a modification and added $ at the end of the third line before [nc].. and change 301,nc to 301,L and its working now!

    Source: http://kikk.in/htaccess-file-to-add-www-in-the-url/

     
    • Thanks techman, though I believe I’ve had this working for a few projects. I’ll verify and update as necessary though, thanks!

       

Leave a Comment

You must be logged in to post a comment. Log in »

Copyright © 2011 Agee Design. All Rights Reserved.