Jun 28, 2007
How to redirect index.php to root... One of the ground rules for successful SEO is to have only one url for each page. We need to combine all the Google PR and link power into one url. Typically, the index page can be accessed by both domain.com/index.php or domain.com/index.html as well as domain.com.Where is the index.php link used on a website - Many people have a link on the home button as <a href="/index.php">. This should be <a href="/">. So in reality, there should never be any links into either index.php, nor index.php.
However, should such links exist, or as general good practice, there should be a redirect back to the root if ever such a link happened to exist.
.htaccess file - in the root directory
RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ http://www.domain.com/$1 [R=301,L]
Refer to the Redirect check tool for an answer specific to your site.



Comments
BALI DIRECTORY - Jul 8, 2007
great tips,
solving my problems for good indexing.
thanks you for posting this article.
Michael Brandon - Jul 8, 2007
Great that it could help you. And great to see that this redirecting index.html to root / redirecting index.php to root is nice and high on the search engines. Always reassuring to see that good SEO works! Get it all right, and Google is your friend.
Robert - Jul 15, 2007
I ran your redirect check tool and found I had 6 pages returning a 200 status, and then tried following your techniques at the bottom on the page and checked my page again with the checker and it told me all is ok.
However, my site wont display in a browser, its like it can't find it.
Any ideas on that?
Michael Brandon - Jul 15, 2007
Take off your changes, and add them one at a time, checking each time that it still works.
And post your website to this thread so we can see.
Robert - Jul 16, 2007
Hi Michael,
The website is http://ezwd.co.nz. As you can see there are 6 pages all returning a 200 status. Another thing is you have PHP code there, what if my pages are html does that mean i have to make it php, just to include the header?
Cheers,
Robert
Michael Brandon - Jul 18, 2007
Have a try now. I have just updated the redirect tools page. Let me know how you get on.
Robert - Aug 17, 2007
Brilliant Michael, sorry about the late reply. I shouldnt have to include both the php and the htaccess versions of this redirect do i? at this stage i have just implemented the .htaccess version and i get the "all looks ok chief", this is suffecient for good seo practise is it?
Michael Brandon - Aug 17, 2007
Is your website http://www.ezwd.co.nz ??? I am able to currently access it via both the www and non www, as well as via /index.html. There are no redirects.
The point is that each are unique url's that could get listed on Google and receive inbound links in the own right. Its best to settle on one, and have redirects to the others.
Robert - Aug 17, 2007
Right, yea i do understand, No i tried it on another site that i have. But the website above should be working ok now.
Michael Brandon - Aug 17, 2007
Looks all good.
Robert - Aug 17, 2007
Cheers for your help :-)
JF - Oct 29, 2007
Hi i have a question i ran a blog that is at http://www.citronet.ca/blog/index.php i've made a redirection to use www But i would like to remove the index.php...Is theres a difference if i use query_string?
and that my index is in the blog folder?
Options +FollowSymLinks
RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ http://www.citronet.ca/blog$1 [R=301,L]
I would like to be able to access to http://www.citronet.ca for my web site and http://www.citronet.ca/blog for my weblog i guess that the article for my blog will be http://www.citronet.ca/blog?post/2007/10/28/link-to
Or is there a better way?
Thanks
Michael Brandon - Oct 29, 2007
Yes, while the recommended script works to redirect all instances of index.php etc to the root of their directories, if you have a .htaccess file in any directory, you will need to use your suggested htaccess script in that directory as well.
Personally I find .htaccess hard work to get right first time. I take the concepts, and generally get success after trying several alternatives.
prem ypi - Feb 26, 2009
Thanks a lot for suggesting the htaccess way. But i needed to find the php way to do it. What code should i put in php file itself so that index.php gets redirected to /
Simply using SCRIPT_NAME server variable loops infinitely and reports problem.
team fortress - Apr 17, 2009
Thank you for posting this redirect code. My forum has been online for a little over tw years. During that time a lot of my members have posted a link back to my site. But they included the index.php.
The main html root - without index.php has a Google Page Rank of 4. The index.php page page rank of 3. I wonder what my page rank would be if I would have this in effect since the day my site launched.
Pepe - Oct 2, 2009
Working perfectly on my site!
Thanks!
Offshore Seedboxes - Offshore Seedboxes - Nov 1, 2009
Thanks, I changed mine to redirect the index.html and worked perfect.
Options +FollowSymLinks
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ http://www.domain.com/$1 [R=301,L]
Bernard Walsh - Personal Injury Attorney - Nov 16, 2010
thanks worked like a charm - used it on our site to fix the links