.htaccess Redirect – Automatically add www

Web developers normally face this issue where client complains about website ‘WEBSITE_NAME.com’ should automatically add WWW while accessing via browser.

So if we write being-yourself.com in the website, it should be redirected to www.being-yourself.com

Solution: Solution is simple for wordpress based websites.  All you have to do is, Login to Dashboard, navigate to Settings –> General Node and change URL there.

For non-wordpress website, it can be done either via header redirect or via .htaccess redirect.

Adding following lines to .htaccess will do the required:

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

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *