Force to browse your site with www using htaccess

If your domain is indexed using www and without www, your site ranks will be shared so you should tell Search Engines to index only with one name. On google webmaster tool, there is an option to do that.

Also you can force your visitors, bots to browse your site with only one name, either with www or without www. Here is two lines of code you have to add to your htaccess file to force them to browse site with www –

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Sometime it is useful.

Advertisements

6 thoughts on “Force to browse your site with www using htaccess

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s