2

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

Community
  • 1
  • 1
alex
  • 479,566
  • 201
  • 878
  • 984

1 Answers1

2

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
  • 38,186
  • 16
  • 91
  • 120
  • 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 May 25 '09 at 04:24
  • moved the slash to the back of the index.php string. does it match now? – SpliFF May 25 '09 at 06:15
  • note. it could now technically match my_index.php as well but I suspect that's unlikely to happen – SpliFF May 25 '09 at 06:18