| Quick Search |
If you would like to redirect all non-www requests to your site to the www version, you need to add the following code to your .htaccess file:
in 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://your-domain.com to http://www.your-domain.com. There are some benefits from doing that:
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.
If you want to do the opposite, the code is very similar:
in your .htaccess file
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!
Posted in PHP Development
You can follow any responses to this entry through the RSS 2.0 Feed. You can leave a response , or trackback from your own site.
search engine marketing company India that offers affordable seo services