Forum Moderators: phranque
My mod_rewrite aproach is:
1 and 2: Rewrite to [mydomain...]
3: Compose the cgi string based on Environmental variables
1.RewriteCond %{REQUEST_FILENAME} ^\/([^_]+)_([^_]+)
2.RewriteRule ^.*$ [mydomain...] [env=adr1:%1,env=adr2:%2]
3.RewriteRule ^.*$ /cgi-bin/to.cgi?id=%{env=adr1}&id2=%{adr2} [L]
Line 2 is working, the log shows: ... setting env variable 'adr2' to '000000'
but the values are not inserted into line 3 - in none of the both syntax forms I tried.
How may I insert {env=adr1} in line 3?
Thanks, Maggi
I need the environment variables for later use in the template.
When not forcing a redirect, the ENV are passed and I can see them in a SSI page with <!--#printenv --> and in the template called by the perl script.
RewriteRule ^\/2/([^_]+)_([^_]+)\.html$ /2/$1.html [E=AAAA:$1,E=BBBB:$2,L]
The problem is, that when I include a Redirect=301 in the RewriteRule, than the environment variables are _not_ passed.
That might be a reason from the second (redirected) call by the browser?
Is there a way to store the environment variables inside mod_rewrite from the status like in RewriteCond to the?
So, the answer, as you quoted from devshed below, is to attach the info you need to pass through to the next HTTP request to the redirected URL in the form of a query string, i.e., [yourdomain.com...] or perhaps to pass this info in the form of subdomains (http://%1.%2.mydomain.com/%1.html), or to use cookies.
You may wish to re-think your whole approach based on this, and I don't claim to know or understand the reasons you need to do this, so I won't elaborate more. But I hear the shades of Occam and Einstein, saying, "Given two choices of equal merit, the simplest one is usually best," and, "Make everything as simple as possible, but no simpler." And Ben Franklin chiming in with, "Eschew obfuscation."
When using
RewriteCond %{REQUEST_FILENAME} ^\/2/([^_]+)_([^_]+)\.html
RewriteRule ^.*$ RewriteCond %{REQUEST_FILENAME} ^\/2/([^_]+)_([^_]+)\.html
RewriteRule ^.*$ /2/%1.html [E=AAAA:%1,E=BBBB:%2,R=301,L]
I get the the page mydomain/2/%1.html with the value vor %1 as existent in the calling url.,
but not the environment variables analysed in the RewriteCond.
I found a note in
[forums.devshed.com...]
"Ok, first of all, there is NO way to pass environment variables through an external URL-to-URL redirect. The only way is QUERY_STRING parameters."
In the case above it is a not a external redirect (and the same result ocures when using a url-to-file redirect).
The question is:
How may I maintain the environment variables and pass them to the redirected page?
Jim