Apache2 - mod_rewrite : RequestHeader and environment variables
Posted
by Guillaume
on Server Fault
See other posts from Server Fault
or by Guillaume
Published on 2009-08-04T08:10:35Z
Indexed on
2010/04/11
17:03 UTC
Read the original article
Hit count: 666
I try to get the value of the request parameter "authorization" and to store it in the header "Authorization" of the request.
The first rewrite rule works fine. In the second rewrite rule the value of $2 does not seem to be stored in the environement variable. As a consequence the request header "Authorization" is empty.
Any idea ? Thanks.
<VirtualHost *:8010>
RewriteLog "/var/apache2/logs/rewrite.log"
RewriteLogLevel 9
RewriteEngine On
RewriteRule ^/(.*)&authorization=@(.*)@(.*) http://<ip>:<port>/$1&authorization=@$2@$3 [L,P]
RewriteRule ^/(.*)&authorization=@(.*)@(.*) - [E=AUTHORIZATION:$2,NE]
RequestHeader add "Authorization" "%{AUTHORIZATION}e"
</VirtualHost>
I need to handle several cases because sometimes parameters are in the path and sometines they are in the query. Depending on the user. This last case fails. The header value for AUTHORIZATION looks empty.
# if the query string includes the authorization parameter
RewriteCond %{QUERY_STRING} ^(.*)authorization=@(.*)@(.*)$
# keep the value of the parameter in the AUTHORIZATION variable and redirect
RewriteRule ^/(.*) http://<ip>:<port>/ [E=AUTHORIZATION:%2,NE,L,P]
# add the value of AUTHORIZATION in the header
RequestHeader add "Authorization" "%{AUTHORIZATION}e"
© Server Fault or respective owner