I'm focusing on an internet site that passes all PHP scripts via a single PHP page (passthrough.php).

The .htaccess file is supposed to consider certain special sites and translate them into GET variables, therefore the controller script knows what related to them. So:








And so forth. This is exactly what I've during 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]

During my second example, mod_rewrite executes the ajax rule, it appears like it executes the passthrough.php rule. Then, it appears to operate the rewrite process. The ajax rule doesn't fit, however the output rule does, to ensure that is used, and so the URL is finally rewritten again through the passthrough.php rule, which leads to the next GET vars:

path: method.php/json/method.php/json/method output: json mode: ajax

My real question is this: it is possible to method of getting the rewrite engine to process the entire URL all at once? therefore the url is available 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 appears to become running with the .htaccess once for every rule that's matched up, rather than parsing the URL, altering in line with the next rule, altering in line with the next rule, and so forth.

I have attempted using some of the flags, incuding [PT] and [S], but they are poorly-recorded. The problem could be solved by writing special conditions which pass the code straight to the passthrough script, but this isn't well-damaged out and doesn't 'feel' to me.

Do this:

RewriteRule ^passthrough\.php$ - [L]
RewriteRule !\.php$ - [L]
RewriteRule ^ajax/(.*) passthrough.php?path=$1&mode=ajax [L,QSA]
RewriteRule ^(xml|json)/(.*) passthrough.php?path=$2&output=$1 [L,QSA]

Honestly, I believe you are wrong to express that passing the PATH_INFO into passthrough.php and parsing it inside your script. You are in for a maintenance nightmare by (ab)using mod_rewrite how you are.

womble, have you got a better method of doing such things as this?