Remove index.php from url

One issue many web masters run into is the problem of having multiple URLs where you can access the homepage of your site.

For example, there are some sites you can access by going to:,, and

In a previous post I talked about either forcing www or no www for your domain. In this post I will show you how to check to see if /index.php is requested, and how to remove it.

The solution is a rather simple .htaccess rule:

RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/
RewriteRule ^(([^/]+/)*)index\.php$ http://%{HTTP_HOST}/$1 [R=301,L]

Let me break down the lines for you. The first line simply turns on the RewriteEngine. Don’t include this line if RewriteEngine On is already present in your .htaccess file.

The second line checks the HTTP REQUEST for index.php. And the third line redirects the user to the domain, without the /index.php.

This is important as well. You will want to check your website to see if you link to the version of your website anywhere. If you do, you will want to change it to link to the version instead.

I’ve recently seen a few websites where the is PR6, but the is PR4. This causes Google to treat the pages as two separate pages, and can hurt you in rankings. Don’t let this happen to you!

Be Sociable, Share!
  1. #1 by Riak on May 24, 2011 - 4:28 am

    Thankyou so much, I have tried loads of diffrent appache codes and none work except yours! :-)

  2. #2 by Javier Pacheco on June 22, 2011 - 7:16 am

    Nice tip, simple and neat.

    And actually makes Google web crawling better.

  3. #3 by ashley on April 15, 2012 - 3:33 am

    great tut, how do we do the same for pages in directories i.e

Comments are closed.