.htaccess redirect index.php to /

Nikki Wilson picture Nikki Wilson · Feb 6, 2013 · Viewed 21.8k times · Source

I would like to hide the index.php page and just show the domain.

Is this possible with .htaccess?

RewriteRule ^index\.php/?$ / [L,R=301,NC]

Also tried:

RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /index.php HTTP/
RewriteRule ^index.php$ http://example.com/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

index.php still shows

Answer

Satish picture Satish · Feb 6, 2013

Try, It works for me! Make sure your have AllowOverride All set in httpd.conf

RewriteEngine On 

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

There is a regex issue in your rules, I have modified your rules and it works for me:

RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} index\.php
RewriteRule ^index\.php$ http://example\.com/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index\.php [L]