You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Suneet Shah <su...@gmail.com> on 2011/09/24 22:06:00 UTC
Re: [users@httpd] Mod-ReWrite
Hi,
i am still having some problem with getting this to work. I am not getting
the value that is in the query string to appear in the header.
Any ideas on what I am doing wrong?
I have the following url:
http://localhost/test_rpc/header.jsp?tkn=abc
In my httpd.conf I added the following:
RewriteEngine on
Options +FollowSymLinks
RewriteCond %{QUERY_STRING} tkn=(.*)
RewriteRule ^/test_rpc/$ [E=var1:%1]
RequestHeader append tkn var1
In my test, the Header "tkn" shows up with a value of "var1", instead of
"abc" which is on the query string.
Thanks in advance for your help
suneet
On Wed, Sep 21, 2011 at 1:20 AM, Igor Cicimov <ic...@gmail.com> wrote:
> Hi mate,
>
> Try something like this for the example you gave
> http://host/myapp?userid=abc&role=myrole:
>
> RewriteEngine on
> Options +FollowSymLinks <http://host/myapp?userid=abc&role=myrole>
> RewriteCond QUERY_STRING userid=(.*)&role=(.*)
> RewriteRule ^/myapp$ [E=var1:%1,var2:%2]
>
> RequestHeader append userid var1
> RequestHeader append role var2
>
> This is untested and not sure about the correct syntax in the
> [E=var1:%1,var2:%2] flag, ie do you need coma or ; between the vars etc, but
> thats the general idea.
>
> Cheers,
> Igor
> On Wed, Sep 21, 2011 at 8:51 AM, Suneet Shah <su...@gmail.com>wrote:
>
>> Thanks Igor.
>>
>> Would you be able to point me to an example? I dont fully understand how I
>> can configure this to take a parameter of the query string and then set a
>> variable as a header.
>>
>> thanks for your help
>>
>>
>>
>> On Tue, Sep 20, 2011 at 6:29 PM, Igor Cicimov <ic...@gmail.com> wrote:
>>
>>> Use mod_rewrite to set variable and then set that var as header.
>>> On Sep 21, 2011 7:32 AM, "Suneet Shah" <su...@gmail.com>
>>> wrote:
>>> > Hello,
>>> >
>>> > I had a question about Mod-Proxy and Mod_headers
>>> >
>>> > 1) Is it possible to take a values that are on a query string and pass
>>> them
>>> > as headers? If so how?
>>> > For example, if I have:
>>> >
>>> > http://host/myap?userid=abc&role=myrole
>>> > I would like to take the values in the query string and pass them as
>>> headers
>>> > to the app that I am proying to
>>> >
>>> > 2) I would like to pass the above headers or query string parameters on
>>> > every request.
>>> > How can I do this? Is there a way to put these values in session have
>>> have
>>> > them passed as headers every time?
>>> >
>>> > If there is a better appraoch for the above, please let me know.
>>> >
>>> > thanks in advance for your help
>>> > suneet
>>>
>>
>>
>
Re: [users@httpd] Mod-ReWrite
Posted by Mark Montague <ma...@catseye.org>.
On September 24, 2011 23:04 , Suneet Shah <su...@gmail.com> wrote:
> I tried to add another parameter to the query string and now the
> different parameters are getting merged together
> I am not sure if my error is in the RewriteCond or in the ReWriteRule.
> Any ideas?
>
> URL -> http://localhost/test_rpc/header.jsp?tkn=xyz&userid=mylogin
> <http://localhost/test_rpc/header.jsp?tkn=xyz&userid=mylogin>
> HEADERS PASSED:
> tkn: xyz;var2:mylogin
> userid: (null)
>
> RewriteCond %{QUERY_STRING} tkn=(.*)&userid=(.*)
> RewriteRule ^/test_rpc - [E=var1:%1;var2:%2]
> RequestHeader append tkn %{var1}e
> RequestHeader append userid %{var2}e
You would have less problems if you read and followed the
documentation. From https://httpd.apache.org/docs/2.2/rewrite/flags.html
> Flags are included in square brackets at the end of the rule, and
> multiple flags are separated by commas.
>
> |RewriteRule pattern target [Flag1,Flag2,Flag3]|
>
The rewrite rule you have above says "set the environment variable named
'var1' to have the value of the first subexpression matched in the
rewrite condition, followed by the literal string ';var2:', followed by
the value of the second subexpression matched in the rewrite
condition." This is exactly what you wind up getting as the value of
the tkn header above.
There is nothing in the documentation that says that the E flag
understands multiple arguments separated by semicolons -- it does not.
If you want to set multiple environment variables, you have to use the E
flag multiple times.
What you wanted is probably
RewriteRule ^/test_rpc - [E=var1:%1,E=var2:%2]
Please take the time to read and understand the documentation
thoroughly. This will save you time in the end and be much less
frustrating.
--
Mark Montague
mark@catseye.org
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] Mod-ReWrite
Posted by Suneet Shah <su...@gmail.com>.
Sorry, please disregard my question.
I found my error.
On Sat, Sep 24, 2011 at 11:04 PM, Suneet Shah <su...@gmail.com>wrote:
> I tried to add another parameter to the query string and now the different
> parameters are getting merged together
> I am not sure if my error is in the RewriteCond or in the ReWriteRule. Any
> ideas?
>
> URL -> http://localhost/test_rpc/header.jsp?tkn=xyz&userid=mylogin
> HEADERS PASSED:
> tkn: xyz;var2:mylogin
> userid: (null)
>
> RewriteCond %{QUERY_STRING} tkn=(.*)&userid=(.*)
> RewriteRule ^/test_rpc - [E=var1:%1;var2:%2]
>
> RequestHeader append tkn %{var1}e
> RequestHeader append userid %{var2}e
>
> thanks for your help
>
>
>
> On Sat, Sep 24, 2011 at 10:44 PM, Suneet Shah <su...@gmail.com>wrote:
>
>> Mark,
>>
>> Many thanks for your help. This now works
>>
>> Suneet
>>
>>
>>
>> On Sat, Sep 24, 2011 at 10:33 PM, Mark Montague <ma...@catseye.org> wrote:
>>
>>> On September 24, 2011 22:23 , Suneet Shah <su...@gmail.com>
>>> wrote:
>>>
>>>> I made the change that you described below. Now the tkn header is coming
>>>> in as null. Have I made an error in assigning the tkn to var1?
>>>>
>>>> URL -> http://localhost/test_rpc/**header.jsp?tkn=abc<http://localhost/test_rpc/header.jsp?tkn=abc>
>>>> Header value -> tkn: (null)
>>>>
>>>> RewriteCond %{QUERY_STRING} tkn=(.*)
>>>> RewriteRule ^/test_rpc/$ [E=var1:%1]
>>>> RequestHeader append tkn %{var1}e
>>>>
>>>
>>> No, the problem is that the rewrite rule you have above tests for a path
>>> component that exactly matches /test_rpc/ with nothing before it and nothing
>>> after it. The URL you are testing with has a path component of
>>> /test_rpc/header.jsp -- so this does not match, the rewrite rule does not
>>> get invoked, and the 'var1' environment variable does not get set.
>>>
>>> To get a rewrite rule that tests for the correct thing, see
>>> https://httpd.apache.org/docs/**2.2/rewrite/<https://httpd.apache.org/docs/2.2/rewrite/>in particular the "Introduction to regular expressions and mod_rewrite"
>>> section.
>>>
>>> Also, you appear to be missing the second argument of the rewrite rule.
>>> If you don't want to perform a substitution, then the substitution argument
>>> (the argument after the pattern argument and before the flags argument)
>>> needs to be a single dash ("-" without the quotes).
>>>
>>> --
>>>
>>> Mark Montague
>>> mark@catseye.org
>>>
>>>
>>
>
Re: [users@httpd] Mod-ReWrite
Posted by Suneet Shah <su...@gmail.com>.
I tried to add another parameter to the query string and now the different
parameters are getting merged together
I am not sure if my error is in the RewriteCond or in the ReWriteRule. Any
ideas?
URL -> http://localhost/test_rpc/header.jsp?tkn=xyz&userid=mylogin
HEADERS PASSED:
tkn: xyz;var2:mylogin
userid: (null)
RewriteCond %{QUERY_STRING} tkn=(.*)&userid=(.*)
RewriteRule ^/test_rpc - [E=var1:%1;var2:%2]
RequestHeader append tkn %{var1}e
RequestHeader append userid %{var2}e
thanks for your help
On Sat, Sep 24, 2011 at 10:44 PM, Suneet Shah <su...@gmail.com>wrote:
> Mark,
>
> Many thanks for your help. This now works
>
> Suneet
>
>
>
> On Sat, Sep 24, 2011 at 10:33 PM, Mark Montague <ma...@catseye.org> wrote:
>
>> On September 24, 2011 22:23 , Suneet Shah <su...@gmail.com>
>> wrote:
>>
>>> I made the change that you described below. Now the tkn header is coming
>>> in as null. Have I made an error in assigning the tkn to var1?
>>>
>>> URL -> http://localhost/test_rpc/**header.jsp?tkn=abc<http://localhost/test_rpc/header.jsp?tkn=abc>
>>> Header value -> tkn: (null)
>>>
>>> RewriteCond %{QUERY_STRING} tkn=(.*)
>>> RewriteRule ^/test_rpc/$ [E=var1:%1]
>>> RequestHeader append tkn %{var1}e
>>>
>>
>> No, the problem is that the rewrite rule you have above tests for a path
>> component that exactly matches /test_rpc/ with nothing before it and nothing
>> after it. The URL you are testing with has a path component of
>> /test_rpc/header.jsp -- so this does not match, the rewrite rule does not
>> get invoked, and the 'var1' environment variable does not get set.
>>
>> To get a rewrite rule that tests for the correct thing, see
>> https://httpd.apache.org/docs/**2.2/rewrite/<https://httpd.apache.org/docs/2.2/rewrite/>in particular the "Introduction to regular expressions and mod_rewrite"
>> section.
>>
>> Also, you appear to be missing the second argument of the rewrite rule.
>> If you don't want to perform a substitution, then the substitution argument
>> (the argument after the pattern argument and before the flags argument)
>> needs to be a single dash ("-" without the quotes).
>>
>> --
>>
>> Mark Montague
>> mark@catseye.org
>>
>>
>
Re: [users@httpd] Mod-ReWrite
Posted by Suneet Shah <su...@gmail.com>.
Mark,
Many thanks for your help. This now works
Suneet
On Sat, Sep 24, 2011 at 10:33 PM, Mark Montague <ma...@catseye.org> wrote:
> On September 24, 2011 22:23 , Suneet Shah <su...@gmail.com>
> wrote:
>
>> I made the change that you described below. Now the tkn header is coming
>> in as null. Have I made an error in assigning the tkn to var1?
>>
>> URL -> http://localhost/test_rpc/**header.jsp?tkn=abc<http://localhost/test_rpc/header.jsp?tkn=abc>
>> Header value -> tkn: (null)
>>
>> RewriteCond %{QUERY_STRING} tkn=(.*)
>> RewriteRule ^/test_rpc/$ [E=var1:%1]
>> RequestHeader append tkn %{var1}e
>>
>
> No, the problem is that the rewrite rule you have above tests for a path
> component that exactly matches /test_rpc/ with nothing before it and nothing
> after it. The URL you are testing with has a path component of
> /test_rpc/header.jsp -- so this does not match, the rewrite rule does not
> get invoked, and the 'var1' environment variable does not get set.
>
> To get a rewrite rule that tests for the correct thing, see
> https://httpd.apache.org/docs/**2.2/rewrite/<https://httpd.apache.org/docs/2.2/rewrite/>in particular the "Introduction to regular expressions and mod_rewrite"
> section.
>
> Also, you appear to be missing the second argument of the rewrite rule. If
> you don't want to perform a substitution, then the substitution argument
> (the argument after the pattern argument and before the flags argument)
> needs to be a single dash ("-" without the quotes).
>
> --
>
> Mark Montague
> mark@catseye.org
>
>
Re: [users@httpd] Mod-ReWrite
Posted by Mark Montague <ma...@catseye.org>.
On September 24, 2011 22:23 , Suneet Shah <su...@gmail.com> wrote:
> I made the change that you described below. Now the tkn header is
> coming in as null. Have I made an error in assigning the tkn to var1?
>
> URL -> http://localhost/test_rpc/header.jsp?tkn=abc
> Header value -> tkn: (null)
>
> RewriteCond %{QUERY_STRING} tkn=(.*)
> RewriteRule ^/test_rpc/$ [E=var1:%1]
> RequestHeader append tkn %{var1}e
No, the problem is that the rewrite rule you have above tests for a path
component that exactly matches /test_rpc/ with nothing before it and
nothing after it. The URL you are testing with has a path component of
/test_rpc/header.jsp -- so this does not match, the rewrite rule does
not get invoked, and the 'var1' environment variable does not get set.
To get a rewrite rule that tests for the correct thing, see
https://httpd.apache.org/docs/2.2/rewrite/ in particular the
"Introduction to regular expressions and mod_rewrite" section.
Also, you appear to be missing the second argument of the rewrite rule.
If you don't want to perform a substitution, then the substitution
argument (the argument after the pattern argument and before the flags
argument) needs to be a single dash ("-" without the quotes).
--
Mark Montague
mark@catseye.org
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] Mod-ReWrite
Posted by Suneet Shah <su...@gmail.com>.
Hi,
thanks very much for your help with this. I am a bit unclear in how
information is assigned to variables and how they can be passed from one
directive to another.
I made the change that you described below. Now the tkn header is coming in
as null. Have I made an error in assigning the tkn to var1?
URL -> http://localhost/test_rpc/header.jsp?tkn=abc
Header value -> tkn: (null)
RewriteCond %{QUERY_STRING} tkn=(.*)
RewriteRule ^/test_rpc/$ [E=var1:%1]
RequestHeader append tkn %{var1}e
Thanks for your help
Suneet
On Sat, Sep 24, 2011 at 4:25 PM, Mark Montague <ma...@catseye.org> wrote:
> On September 24, 2011 16:06 , Suneet Shah <su...@gmail.com>
> wrote:
>
>> I have the following url:
>> http://localhost/test_rpc/**header.jsp?tkn=abc<http://localhost/test_rpc/header.jsp?tkn=abc>
>>
>> In my httpd.conf I added the following:
>>
>> RewriteEngine on
>> Options +FollowSymLinks
>>
>> RewriteCond %{QUERY_STRING} tkn=(.*)
>> RewriteRule ^/test_rpc/$ [E=var1:%1]
>> RequestHeader append tkn var1
>>
>> In my test, the Header "tkn" shows up with a value of "var1", instead of
>> "abc" which is on the query string.
>>
>
>
> The RequestHeader directive you currently have means "append the literal
> string 'var1' to the value of the header named 'tkn'"; this is why you are
> seeing the above result in your test. The RequestHeader directive does not
> know that you want it to interpret 'var1' as the name of an environment
> variable, because you have not told it to do so.
>
> In order to append the value of the environment variable named 'var1' to
> the header named 'tkn', try
>
> RequestHeader append tkn %{var1}e
>
> For more information, see
>
> https://httpd.apache.org/docs/**2.2/mod/mod_headers.html#**requestheader<https://httpd.apache.org/docs/2.2/mod/mod_headers.html#requestheader>
> https://httpd.apache.org/docs/**2.2/mod/mod_headers.html#**header<https://httpd.apache.org/docs/2.2/mod/mod_headers.html#header>
>
> --
> Mark Montague
> mark@catseye.org
>
>
Re: [users@httpd] Mod-ReWrite
Posted by Mark Montague <ma...@catseye.org>.
On September 24, 2011 16:06 , Suneet Shah <su...@gmail.com> wrote:
> I have the following url:
> http://localhost/test_rpc/header.jsp?tkn=abc
>
> In my httpd.conf I added the following:
>
> RewriteEngine on
> Options +FollowSymLinks
>
> RewriteCond %{QUERY_STRING} tkn=(.*)
> RewriteRule ^/test_rpc/$ [E=var1:%1]
> RequestHeader append tkn var1
>
> In my test, the Header "tkn" shows up with a value of "var1", instead
> of "abc" which is on the query string.
The RequestHeader directive you currently have means "append the literal
string 'var1' to the value of the header named 'tkn'"; this is why you
are seeing the above result in your test. The RequestHeader directive
does not know that you want it to interpret 'var1' as the name of an
environment variable, because you have not told it to do so.
In order to append the value of the environment variable named 'var1' to
the header named 'tkn', try
RequestHeader append tkn %{var1}e
For more information, see
https://httpd.apache.org/docs/2.2/mod/mod_headers.html#requestheader
https://httpd.apache.org/docs/2.2/mod/mod_headers.html#header
--
Mark Montague
mark@catseye.org
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org