abullrich abullrich - 6 months ago 68
Apache Configuration Question

Use ENV variable within regex

I'm trying to use some created local variables as part of the validations required by the regular expression. My code so far:

RewriteCond %{HTTP_REFERER} .*redirect=(.*?)(?:&.*|$)
RewriteRule .* - [E=REDIRECT:%1]

RewriteCond %{THE_REQUEST} \/(.*?)(?:\/-*|\s)
RewriteRule .* - [E=TEST_IDEA:%1]

RewriteCond %{ENV:REDIRECT} =%{ENV:TEST_IDEA} ###This doesn't work as '=' takes %{ENV:TEST_IDEA} lexicographically.
RewriteRule .* - [F]

As a tangential point, I'm trying to validate that both the referer and the GET method for a URL share something in common.


You can use ap_expr comparisons if you pass in the first argument to RewriteCond as literal expr:

RewriteCond expr "%{ENV:REDIRECT} = %{ENV:TEST_IDEA}"
RewriteRule ^ - [F]