views:

68

answers:

1

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?

More info here about my .htaccess

+2  A: 

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

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

This should be the only rule, no need for the RewriteCond's as well

SpliFF
This rule doesn't work where the URL starts with index.php/something like in the 1st example. It does work with the other examples, however.
alex
moved the slash to the back of the index.php string. does it match now?
SpliFF
note. it could now technically match my_index.php as well but I suspect that's unlikely to happen
SpliFF
I will try tomorrow, thanks Spliff +1
alex