Redirect index.html to Root htaccess

How do I redirect index.html? How about index.php to root or home page? I 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, I 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 I did it.

How to Redirect both index.html and index.php to Root

In the following examples, replace yoursite.com with your actual site.

  1. First, login via an ftp client to the directory of your site.
  2. Next, copy the .htaccess file to your desktop.
  3. Now, using a text editor (I prefer notepad++), open the file.
  4. Then, at the top of the .htaccess file add the following code;
    Options +FollowSymLinks
    RewriteCond %{THE_REQUEST} ^.*/index.html
    RewriteRule ^(.*)index.html$ https://www.yoursite.com/$1 [R=301,L]
    RewriteCond %{THE_REQUEST} ^.*/index.php
    RewriteRule ^(.*)index.php$ https://www.yoursite.com/$1 [R=301,L]
  5. Finally, save the changes and upload the .htaccess file to your server, replacing the old file.

How to Redirect index.html to Home Page to Root

  1. Login via an ftp client to the folder containing your site.
  2. Copy the .htaccess file to your desktop.
  3. Using your text editor, open the file.
  4. Add the following code to the top of the file;
    Options +FollowSymLinks
    RewriteCond %{THE_REQUEST} ^.*/index.html
    RewriteRule ^(.*)index.html$ https://www.yoursite.com/$1 [R=301,L]
  5. Save the changes and upload the .htaccess file to your server.

How to Redirect index.php to Root or 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. Next, copy the .htaccess file to your desktop.
  3. Then, open the file with a text editor.
  4. Add the following code to the top of the file;
    Options +FollowSymLinks
    RewriteCond %{THE_REQUEST} ^.*/index.php
    RewriteRule ^(.*)index.php$ https://www.yoursite.com/$1 [R=301,L]
  5. Finally, save your changes and then upload the .htaccess file to your server, replacing the old file.

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. yoursite.com

Enjoy!