I am using these rules and conditions in .htaccess to turn these
http://www.example.com/index.php/about/history
http://www.example.com/about/history/index.php
into
http://www.example.com/about/history
.htaccess
# ensure there is no /index.php in the address bar
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
RewriteRule ^(.*)index\.php$ $1 [R=301,L,NS]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index\.php(.*)\ HTTP/ [NC]
RewriteRule ^index\.php/(.*) $1 [NS,NC,L,R=301]
Except there is a case where if the URL is
http://www.example.com/about/index.php/history/
It will result in an endless loop of redirecting. Now I know this is probably a rarity, but I’d like it not to happen if possible. How can I change my rules to accomodate this?
If I understand correctly you just want to remove index.php whereever it appears? In that case your solution is overly complex. You probably want something like
This should be the only rule, no need for the RewriteCond’s as well