Redirect index.html and index.php to the home page

How to redirect index.html and index.php to the home page. We recently did some website work for a local business. The business was using a static html website and we wanted to convert the site to a WordPress based platform for multiple reasons. During the conversion, we needed to not only perform 301 redirects for all of the currently indexed html pages, but also perform a redirect for the index.html page. This was a bit more complicated as you cannot simply perform a 301 redirect on an index page. Here is how we did it.

Note: In the following examples, replace http://www.yoursite.com/ with your actual site.

How to redirect both index.html and index.php to the home page:

  1. Login via an ftp client to the folder containing your site
  2. Copy the .htaccess file to your desktop
  3. Using a text editor (I prefer notepad++), open the .htaccess file
  4. At the top of the .htaccess file add the following code:
  5. Options +FollowSymLinks
    RewriteCond %{THE_REQUEST} ^.*/index.html
    RewriteRule ^(.*)index.html$ http://www.yoursite.com/$1 [R=301,L]
    RewriteCond %{THE_REQUEST} ^.*/index.php
    RewriteRule ^(.*)index.php$ http://www.yoursite.com/$1 [R=301,L]

  6. Next, save the changes and upload the .htaccess file to your server

How to redirect index.html to the home page:

  1. Login via an ftp client to the folder containing your site
  2. Copy the .htaccess file to your desktop
  3. Using a text editor (I.E. notepad++), open the .htaccess file
  4. At the top of the .htaccess file add the following code:
  5. Options +FollowSymLinks
    RewriteCond %{THE_REQUEST} ^.*/index.html
    RewriteRule ^(.*)index.html$ http://www.yoursite.com/$1 [R=301,L]

  6. Next, save the changes and upload the .htaccess file to your server

How to redirect index.php to the home page:

By default WordPress takes care of redirecting index.php to / however, it's not a bad idea to set a rule for this.

  1. Login via an ftp client to the folder containing your site
  2. Copy the .htaccess file to your desktop
  3. Using a text editor (I.E. notepad++), open the .htaccess file
  4. At the top of the .htaccess file add the following code:
  5. Options +FollowSymLinks
    RewriteCond %{THE_REQUEST} ^.*/index.php
    RewriteRule ^(.*)index.php$ http://www.yoursite.com/$1 [R=301,L]

  6. Next, save the changes and upload the .htaccess file to your server

From now on, any requests made to index.html or index.php depending on which conditions and rules you used, should result in a redirect to the home page I.E. www.yoursite.com

Enjoy! :)