I am working on a website that passes all PHP scripts through a single PHP page (passthrough.php).
The .htaccess file is supposed to take certain special directories and translate them into GET variables, so the controller script knows what to do with them. So:
http://example.com/ajax/method.php
becomes
http://example.com/passthrough.php?path=method.php&mode=ajax
and
http://example.com/ajax/json/method.php
becomes
http://example.com/passthrough.php?path=method.php&mode=ajax&output=json
And so on. This is what I have in my .htaccess file:
RewriteRule ajax/(.*)$ $1?mode=ajax [QSA]
RewriteRule (xml|json)/(.*)$ $2?output=$1 [QSA]
RewriteRule (.*)\.php$ passthrough.php?path=$1 [QSA]
RewriteRule passthrough.php - [L]
In my second example, mod_rewrite executes the ajax rule, then it looks like it executes the passthrough.php rule. Then, it looks to run the rewrite process. Now the ajax rule does not fit, but the output rule does, so that is applied, and then the URL is finally rewritten again by the passthrough.php rule, which results in the following GET vars:
path: method.php/json/method.php/json/method output: json mode: ajax
My question is this: is there a way to get the rewrite engine to process the whole URL in one go? so the url comes in as /ajax/json/method.php, becomes /json/method.php?mode=ajax, then /method.php?mode=ajax&output=json, then /passthrough.php?mode=ajax&output=json&path=method, all in one go? It seems to be running through the .htaccess once for each rule that is matched, instead of parsing the URL, changing based on the next rule, changing based on the next rule, and so on.
I've tried using several of the flags, incuding [PT] and [S], but they're poorly-documented. The issue can be solved by writing special conditions which pass the code directly to the passthrough script, but this is not well-broken out and does not 'feel' right to me.