Adding www to your domain using 301 redirect with htaccess

2008 Nov 19
You can tell the server to automatically append www on each query to your website using .htaccess. That is all incoming requests to a non www query gets forwarded to the host with www prepended before the domain. Although Google treats them equally now, yahoo and live search may not. So its still wise to add them to your website somehow. Its a great advantage to your site especially in terms of search engine optimization.

Here is the .htaccess script that forwards all request without www to your website having the www before the domain name.


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

Please note that this is only possible to websites that are hosted in either Linux or Unix servers running Apache
Tweet this post

Related Entries

1 Comment

One thing to keep in mind is that if you use any type of login system with passwords, it will no longer work with a 301 direct via .htaccess. Nobody seems to give this info...but here it is!

Leave a comment


About Me


Alfredo Sanchez is an internet professional focusing on the study search engines behavior in particular. Supports Free Open Source Software and currently develops applications with it using XAMPP.

Recent Entries

Close