You can try adding something like this to the top of your rules:
RewriteCond %{ENV:URI} ^$
RewriteRule ^(.*)$ - [ENV=URI:$1]
RewriteCond %{ENV:BASE} ^$
RewriteCond %{ENV:URI}::%{REQUEST_URI} ^(.*)::(.*?)\1$
RewriteRule ^ - [ENV=BASE:%2]
And then instead of using RewriteBase
, you'll have to include the BASE
environment variable everywhere. For example:
RewriteRule ^([pdf\.actions]+)$ %{ENV:BASE}/pdf.out.actions.php [QSA]
The conditions do a couple of things, but both rules change nothing in the URI and only add environment variables.
The first condition is necessary because it grabs the requested URI before anything is done to it, and stores it. This is important because the (.*)
grouping in the rule has the base stripped off. We want the unaltered URI with the base stripped off. So the URI
environment variable is the URI with the base stripped off.
The second condition is necessary because it compares the URI
environment variable with the %{REQUEST_URI}
, which is the entire URI, including the base. That comparison yields us the part that was stripped off, or the base, and that'll be stored in the BASE
environment variable.
The conditions which match against ^$
is simply ensuring that this is the first time through the rules (meaning neither of the environment variables have been set). The rewrite engine will loop so we only want to set these the first time.
EDIT: actually, now that I'm looking at it, you could probably leave the first one out:
RewriteCond %{ENV:BASE} ^$
RewriteCond $1::%{REQUEST_URI} ^(.*)::(.*?)\1$
RewriteRule ^(.*)$ - [ENV=BASE:%2]
Using the $1
backreference which matches the rule, noting that the rule itself is partly evaluated (pattern applied) before any of the conditions are checked.