Wednesday, March 2, 2011

Adding a WWW at the beginning of a URL automatically

Hi,

If you want to add a "www" infront of your web URL automatically, here is how you can achieve it. For this you will need a .htaccess file located at the root directory of your website with the following:


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

"my_website" is the name of your website.

Similarly if you want to remove a "www" from the URL:


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

Hope it helps

No comments:

Post a Comment