How to 301 redirect non-www and index.php web site versions to www ones

I normally aim to write one to two blogs per week but the reason I was kinda away this week (apart from the nasty flu I’ve suffered from since Friday night) is due to some development issues with a client’s web site. You see, I consider myself a very good SEO consultant but when it comes to development I know what must be done but not necessarily how to do it, as I have web site developers to do that for me.

I decided through this article to give some technical information about two very well-known SEO issues most companies suffer and most people are not aware of. Through this you will be able to check your own web sites and see if you suffer from similar technical problems and how to solve them.

How to redirect your non-www web site version to the www one.

Whilst working for a client recently, I noticed that her web site was duplicated – what I mean by this is that there were two web site versions online – one without www and one looking like this: (I will use my link so as to keep the client anonymous).

If you type you will be directed to that address, while you should have been redirected to, even if you did not use www on your link bar.

This is a killer SEO situation for the reason that search engines consider these two web sites different, meaning that any potential links from other web sites means that the links will be split.

How did I resolve this? Well, I used a 301 redirect on the non-www version of the URL to the www one by adding some coding, which is essentially a “permanent” redirect in server talk, so now the client can consolidate all of her link popularity to the www version. This eventually will help to increase her website’s chances of obtaining top rankings.

How to redirect index.php to the home page.

The second problem I faced was the /index.php version of the site. Imagine you have your web site appearing as and . Normally the /index.php version should redirect your web site to the non index.php one. I noticed that every single page of the web site had an index.php version. This is again a negative SEO situation. I followed exactly the same procedures as above and now before starting the link building campaign I know for sure that all efforts will be concentrated to one proper web site and not split on two different versions.

How did I solve this?

Drum roll…..I added some coding on the htaccess file of the web site. Please do speak with your web developer before you try and do it on your own web site should you not have experience with coding. The following code applies to appache servers only, your web site might be hosted by a different server. This is what worked for my web site and a client’s web site both using apache:

For the non-www website solution you add this coding:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^
RewriteRule (.*)$1 [R=301,L]

Replace the with your web site link!

For the index.php solution apply this coding:

RewriteEngine On
RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$$1 [R=301,L]

So your final version of the htaccess file (on the top of your notepad and if you wish to make BOTH changes) should be looking like this:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^ [NC]
RewriteRule ^(.*)$$1 [L,R=301]

RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ http://%{SERVER_NAME}/$1 [R=301,L]

You are good to go! Please be aware that if you happen to have a Joomlart web site your administration zone is written on index.php which means you wont be able to access it. I am working on a solution to this right now!

If you test your pages now they should all drive you through the main web page.

If you found this article helpful by any way please +1 one it and share it. It took me a lot of time to solve these issues – let’s make sure people who suffer the same problems find this information and optimise their web pages properly!