Forum Moderators: phranque
However, you cannot use any kind of variables on the "right side" of a RewriteCond.
If you're using later versions of POSIX regular expressions, you can use an "atomic back-reference" and the principle of commutativity to do a "compare." That is, if A+B is equal to A+A, then A=B. This applies to both numeric addition and to string concatenation.
However, this solution is not portable among servers with different OSes (and therefore different regex libraries), so it is recommended to call a script (e.g. PERL) using a RewriteMap if a general solution is required.
Jim
On the mod-rewrite page there is a line that says regarding enviromental variables... "Additionally you can dereference it in a following RewriteCond pattern via %{ENV:VAR}. Use this to strip but remember information from URLs." That led me to believe they can be used in the right side because the right side is the pattern side, correct?
You can go ahead and test the method you'd like to use, but it won't work. :(
Atomic back-references are discussed in many regular expressions tutorials. Take a look at this thread [webmasterworld.com] for a previous discussion of the subject in relation to variable comparison. Additional threads can be found using this search [google.com].
If you use this method, I strongly suggest that you put a 'permanent test rule' at the top of your code -- A rule that will cause the site to fail in an absolutely spectacular manner should your code every be ported to a server that doesn't support this function... or should your server get 'upgraded' to a server version and/or OS that doesn't support this function. I'd suggest comparing a variable to itself using the atomic back-reference, and if this fails, rewrite *all* requested URLs to an error page -- Something that will be immediately noticed, so the server move or upgrade can be aborted ASAP while you code a different solution. Document the hell out of this permanent test rule, so that it won't ever be accidentally/ignorantly removed!
Jim
"<>" are just "virtual" delimiters, so that we don't don't confuse variable-pair values such as "hi hi" and "hih i". This also serves as a 'visual delimiter' for you and whoever else might work on the code and wonder what on earth it does... :)
You could use ">" or "<->" or "~" -- any character or string that's very unlikely to appear in whatever variable you are testing.
Jim