I understand as far as what is happening with my code as to why I'm getting a infinite loop. So I have the following:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^foo/?([^/]+)?/?(.+)? /foo.php?bar=$1&baz=$2 [L,NC]
</IfModule>
So, what is happening is the user is coming in at foo
(or foo/a/b
) and getting redirected to foo.php?bar=$1&baz=$2
. But at this point (and this is where I know I need a more thorough explanation, since I'm sure this is by design) the .htaccess file is being rerun on foo.php?bar=$1&baz=$2
, which matches my rule, and goes into an infinite loop. But I don't know why it is being rerun through my rules.
What is it that I'm not understanding about .htaccess RewriteRule
s?
PS I have solved this immediate problem placing the following commands before the rule, but I would like to know why so I can fix the problem in the future (and so I can remove these lines and do other things instead).
RewriteCondition %{REQUEST_FILENAME} !-f
RewriteCondition %{REQUEST_FILENAME} !-d