Jan-Michael Stone
Jan-Michael Stone

Reputation: 23

Using mod_rewrite to remove index.php completely


I'm looking for a way to remove any file name that is index.php from the URL. The main reason I want to try and do this is because I have directories with "index.php" in them. So instead of getting...
http://localhost/members/index/
I am hoping to achieve something more like...
http://localhost/members/

The code below is currently what I have in my .htaccess file.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} ^GET\ /[^?\s]+\.php
RewriteRule (.*)\.php$ /$1/ [L,R=301]


RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)/$ $1.php [L]

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule .*[^/]$ $0/ [L,R=301]

I really appreciate the help and any suggestions! Thank you so much and God bless!

Upvotes: 0

Views: 174

Answers (2)

Spacedust
Spacedust

Reputation: 1011

Just use this:

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

That's it ;)

Upvotes: 0

Rawkode
Rawkode

Reputation: 22592

If all you want to do is 'remove' index.php from your URLs then you just need to ensure Apache knows that index.php can be used as a directory index.

DirectoryIndex index.php

You can put that in your Apache config, VirtualHost or .htaccess file.

Upvotes: 1

Related Questions