Search code examples
.htaccesshttp-redirect

htaccess - remove "index.php" from URL and redirect


At my website, I was using URL addresses such as

http://me.example.com/index.php?p=home

Then I decided to use

http://me.example.com/?p=home

It all worked automatically without any ".htaccess" file. But addresses which contain "index.php" also still work. Some sites have links to my site in "old" format. I want people to stop using this "old" format and redirect them to the "new" format URL, whenever they use "old" format. All I want to do is to remove "index.php" from URL and also change this URL in visitor's browser.


Solution

  • Here is the code that will go in .htaccess under DOCUMENT_ROOT:

    Options +FollowSymLinks -MultiViews
    # Turn mod_rewrite on
    RewriteEngine On
    RewriteBase /
    
    RewriteRule ^index\.php/?$ / [L,R=301,NC]