mod_rewrite rule and setenv
Asked Answered
P

2

12

Is there anyway to use the value set in a SetEnv on the RewriteRule statement?

Example:

SetEnv MY_SCRIPT myScript.php

rewriteEngine on
RewriteRule ^(.*)$  %{MY_SCRIPT} [L]
Phrenetic answered 23/11, 2009 at 20:10 Comment(0)
E
14

According to http://httpd.apache.org/docs/2.0/env.html the SetEnv is called after the RewriteRule. Therefore it seems to be impossible to use any variable set via SetEnv in a RewriteRule- or RewriteCond-statement.

Using SetEnvIf on the other hand is called before the RewriteRule and therefore Variables set there can be used in a RewriteRule- or RewriteCond-statement.

So something like the following should work:

SetEnvIf SERVER_PROTOCOL "HTTP.*" MY_SCRIPT=myScript.php
rewriteEngine on
RewriteRule ^(.*)$  %{ENV:MY_SCRIPT} [L]
Evalyn answered 2/9, 2011 at 4:45 Comment(0)
D
1

Use %{ENV:MY_SCRIPT} instead of %{MY_SCRIPT}.

Dossal answered 24/11, 2009 at 10:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.