Pawel Szulencki SEO blog, Search Engine Optimization.
.htaccess file is a simple ASCII file created with any text editor such as NotePad. It is a file extension, so you can NOT make it look like “example.htaccess” or “sitename.htaccess”. The file is named .htaccess
.htaccess works within the folder it resides and all sub folders as long as there is no other .htaccess file in any of these sub folders. There can be multiply number of such files on your server, each of them defining different parameters on your server.
How to solve Google canonical issue with .htaccess file?
For Google search engine website addresses with www and without ww are different URl addressess and therefore it may give different PageRanks to those websites. For instance “example.com” and “www.example.com” are different URL’s and they may possess PageRank of 3 and 4. That is very bad situation from SEO point of view as you should always try to keep as much link juice on your site as possible.
There is a fix to that problem. You need to insert the following code into your .htaccess file and put it in the same folder as your homepage:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.com$
RewriteRule ^(.*) http://www.domain.com/$1 [QSA,L,R=301]
Exchange domain with your domain name and that it. All your traffic will be permanently redirected from a non-www version of your website to a www version of your website. That way you will keep all your PageRank on your website and the canonical issue will not arise on your website.
If you prefer to direct all traffic to your non-www version of your website use the following code in your .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteRule ^(.*) http://domain.com/$1 [QSA,L,R=301]
Pawel Szulencki is a SEO (Search Engine Optimization) and Marketing certified specialist who is interested in organic SEO, paid campaigns (PPC) and Social Media Marketing channels.
Pittsburgh SEO Expert (3 comments.)
June 27th, 2008 at 8:57 pm
Great tip I always perfer my domains with non-www. I just think www is completely unnecessary these days.
Pittsburgh SEO Experts last blog post..Get Notified Immediately If You’re Blacklisted By Google
Pawel Szulencki (24 comments.)
June 27th, 2008 at 9:42 pm
Thanks for sharing you opinion Pittsburgh SEO Expert.
I personally prefer domains with www and I think everyone have different preferences about that. Neither way you should decide to use only one format: www or non-www.
My general thinking about that is that we should concentrate on our clients. What is their behavior, what do they prefer. And in my opinion domains should be with www as most people type in domain names with www
But its just my opinion.
Pittsburgh SEO Expert (3 comments.)
July 7th, 2008 at 8:17 pm
Those are really good points. I totally agree that you should concentrate on your clients behavior. When I get a new client I just stick with whatever they’ve been using. If they always type out their links with www then I’d use that.
Pittsburgh SEO Experts last blog post..New Internet Marketing FAQ Page Online
Pawel Szulencki (24 comments.)
July 8th, 2008 at 2:07 pm
Thats a good strategy that works well in all fields. Just give them what they want and they will come for more.
Jeffrey (1 comments.)
July 17th, 2008 at 1:34 pm
I find that this is necessary for canonicalization. The following code will give your /index.html, /index.php or whatever you use as your default page a 301 redirect to http://www.yourdomain.com/:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
RewriteRule ^(.*)index\.php$ /$1 [R=301,L]
Just replace index with whatever file name you are targeting, and replace .php with whatever file extension you use.
Pawel Szulencki (24 comments.)
July 17th, 2008 at 8:22 pm
Hi Jeffrey and welcome to the SEO/SEM blog. Thanks for the .htaccess code. I know many people will find it helpful.
Computer Forum (1 comments.)
July 24th, 2008 at 10:38 pm
My friends will find out about this amazing article! Thanks!