Example:
RewriteCond %{REQUEST_URI}::$1 ^(.*?)/?(.*)::\2$
Looks like this operator is nowhere to find in any reference or manual. Where can I find it or anyone could explain what this operator does?
Rules like this:
RewriteCond %{REQUEST_URI}::$1 ^(.*?/)(.*)::\2$
RewriteRule ^(.*)$ - [E=BASE:%1]
can also be written as (using ##
as fixed delimiter on either side of condition):
RewriteCond %{REQUEST_URI}##$1 ^(.*?/)(.*)##\2$
RewriteRule ^(.*)$ - [E=BASE:%1]
Explanation:
$1
captured from RewriteRule
in your RewriteCond
because mod_rewrite
actually processes a ruleset backwards. It starts with the pattern in the RewriteRule
, and if it matches, goes on to check the one or more RewriteCond
.RewriteCond
, the LHS (left-hand side / test string) can use backreference variables e.g. $1
, $2
OR %1
, %2
etc but RHS (right-hand side) i.e. condition string cannot use these $1
, $2
OR %1
, %2
variables.\1
, \2
etc.RewriteCond
first captured group is (.*?/)
. It will be represented by internal back-reference \1
.RewriteBase
dynamically by comparing %{REQUEST_URI}
and $1
. An example of %{REQUEST_URI}
will be /directory/foobar.php
and example of $1
for same example URI will be foobar.php
. ^(.*?/)::(.*)\1$
is putting the difference in 1st captured group %1
or \1
. Here it will populate %1
or \1
with the value /directory/
which is used later in setting up env variable %{ENV:BASE}
i.e. E=BASE:%1
.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With