Redirect index php to root

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 . This should be . 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

Options +FollowSymLinks
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.

Do this:

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

answered Feb 21, 2012 at 6:02

ThinkingMonkeyThinkingMonkey

12.3k13 gold badges54 silver badges81 bronze badges

8

I based the following code on @ThinkingMonkey's answer

RewriteRule ^(.*)index\.(php|html?)$ /$1 [R=301,NC,L]

It redirects URIs ending with index.php, index.htm or index.html to /. Works with subdirectories, too.

Also, notice the NC flag. It makes it case-insensitive. So it works even if the URI is in upper-case such as INDEX.PHP.

answered Sep 15, 2013 at 23:03

caiosm1005caiosm1005

1,6411 gold badge19 silver badges31 bronze badges

Can be use this

RewriteRule ^index\.php/(.*)$ http://www.example.com/$1 [R=301,L]

Rich Bowen

5,8422 gold badges16 silver badges15 bronze badges

answered Aug 28, 2014 at 12:15

3

Redirecting from index.php to the root of website. That is, from domain.tld/index.php to domain.tld/. Directives for .htaccess file:


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

Commentary

Enable runtime rewriting engine:


RewriteEngine On

If full HTTP request line sent by browser contains "index.php":


RewriteCond %{THE_REQUEST} ^.*/index\.php

Then redirect from domain.tld/index.php to domain.tld/:


RewriteRule ^(.*)index.php$ /$1 [R=301,L]

Notes

  1. Apache Module mod_rewrite docs: http://httpd.apache.org/docs/current/mod/mod_rewrite.html
Web servers
  • Apache + nginx
More
  • Change default index page
  • Deny access to a specific page by IP
  • Deny access to a specific page for an IP address range
  • HTTP to HTTPS redirect in .htaccess
  • HTTPS to HTTP redirect for a single page

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.

  • 1 How to Redirect both index.html and index.php to Root
  • 2 How to Redirect index.html to Home Page to Root
  • 3 How to Redirect index.php to Root or Home Page

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!