From the mind of Jamie Huskisson: From a full-time freelance PHP developer, to the managing director of Rolled Limited

Force www. in your URL using .htaccess

Posted on March 15th, 2007 in ,

Insert this into the top of your .htaccess file, making sure that ‘RewriteEngine On’ comes before it:

RewriteCond %{HTTP_HOST} !^www\.jhuskisson\.com [NC]
RewriteRule ^(.*)$ http://www.jhuskisson.com/$1 [R=301,L]

Replace jhuskisson.com with your chosen domain and make sure if you are placing any full stops within the first line to enter a backslash before each full stop. This will prevent the code from not working.

There are 6 responses to this post so far

Feel free to use any of the following tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>