Nilesh Patel
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Redirecting non-www to www with .htaccess

Go down

Redirecting non-www to www with .htaccess Empty Redirecting non-www to www with .htaccess

Post  Nilesh Patel Tue Oct 22, 2013 4:58 pm

If you want to redirect all non-www requests to your site to the www version, all you need to do is add the following code to your .htaccess file:

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


This will redirect any requests to http://my-domain.com to http://www.my-domain.com. There are several benefits from doing that:

This will redirect any requests to http://my-domain.com to http://www.my-domain.com. There are several benefits from doing that:
- It will avoid duplicate content in Google
- It will avoid the possibility of split page rank and/or split link popularity (inbound links).
- It's nicer, and more consistent.
Note that if your site has already been indexed by Google without the www, this might cause unwanted side effects, like lost of PR. I don't think this would happen, or in any case it would be a temporary issue (we are doing a permanent redirect, 301, so Google should transfer all rankings to the www version). But anyway, use at your own risk!

Something nice about the code above is that you can use it for any website, since it doesn't include the actual domain name.

Redirecting www to non-www

If you want to do the opposite, the code is very similar:

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


In this case we are explicitly typing the domain name. I'm sure it's possible to do it in a generic way, but I haven't had the time to work one out and test it. So remember to change 'my-domain' with your domain name!

In this case we are explicitly typing the domain name. I'm sure it's possible to do it in a generic way, but I haven't had the time to work one out and test it. So remember to change 'my-domain' with your domain name!

For More Info about Redirecting non-www to www with .htaccess

Tags : non www to www, redirecting on www, non www to www with .htaccess, Nilesh Patel, Nilesh Patel-SEO, SEO Services Provider in Ahmedabad, Best Information of world
Nilesh Patel
Nilesh Patel
Admin

Posts : 230
Points : 715
Reputation : 0
Join date : 2012-11-24
Age : 34
Location : Ahmedabad

http://about.me/NileshPatel8

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum