handling parameter in query_string with mod_rewrite

handling parameter in query_string with mod_rewrite

am 16.02.2010 23:21:10 von Stefano Nichele

Hi All,
I would need some help with mod_rewrite :-( .
What I would need is to add an header to the response if the request
contains a URL parameter and the value of that parameter should be used
in that header.

Just to clarify, if the url is:

/download/files/1ytreefecsw?filename=myfile.txt

I would like to return this file /download/files/1ytreefecsw setting in
the response "Content-disposition" header with value myfile.txt:

"Content-disposition: attachment; filename=myfile.txt

I was able to do this thing checking a request header using:
SetEnvIf x-filename "^(.+)$" FILENAME=$1
Header set "Content-disposition" "attachment;
filename=%{FILENAME}e" env=FILENAME

but now i need to do similar thing using a parameter.

I understand that there is not a simple way to access to the
query_string and actually this is not possible using SetEnvIf and it
seems the right way is using mod_rewrite .... but i don't find the
solution.
At the moment i'm trying something like:

RewriteEngine on
RewriteRule ^(.*)filename=(.*)$ $1 [E=FILENAME:$2]
Header set "Content-disposition" "attachment;
filename=%{FILENAME}e" env=FILENAME

but it doesn't work :-((

Could you help me ?

Thanks
ste


------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See 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: handling parameter in query_string with mod_rewrite

am 17.02.2010 00:30:22 von Igor Cicimov

--0050450140ee1c2243047fc01ed1
Content-Type: text/plain; charset=ISO-8859-1

RewriteRule doesn't work with the query part or the URI thus will not work
in your case. You need to try RewriteCond directive combined with
RewriteRule. Something like this maybe?

RewriteEngine On
RewriteCond %{QUERY_STRING} ^(filename=myfile.txt)$
RewriteRule .* - [E=FILENAME:%1]
Header set "Content-disposition" "attachment; filename=%{FILENAME}e"
env=FILENAME

I'm not sure though about the effect of the Header set directive, is it
going to have a global effect afterwords or not?

Igor

On Wed, Feb 17, 2010 at 9:21 AM, Stefano Nichele
wrote:

> Hi All,
> I would need some help with mod_rewrite :-( .
> What I would need is to add an header to the response if the request
> contains a URL parameter and the value of that parameter should be used in
> that header.
>
> Just to clarify, if the url is:
>
> /download/files/1ytreefecsw?filename=myfile.txt
>
> I would like to return this file /download/files/1ytreefecsw setting in the
> response "Content-disposition" header with value myfile.txt:
>
> "Content-disposition: attachment; filename=myfile.txt
>
> I was able to do this thing checking a request header using:
> SetEnvIf x-filename "^(.+)$" FILENAME=$1
> Header set "Content-disposition" "attachment; filename=%{FILENAME}e"
> env=FILENAME
>
> but now i need to do similar thing using a parameter.
>
> I understand that there is not a simple way to access to the query_string
> and actually this is not possible using SetEnvIf and it seems the right way
> is using mod_rewrite .... but i don't find the solution.
> At the moment i'm trying something like:
>
> RewriteEngine on
> RewriteRule ^(.*)filename=(.*)$ $1 [E=FILENAME:$2]
> Header set "Content-disposition" "attachment; filename=%{FILENAME}e"
> env=FILENAME
>
> but it doesn't work :-((
>
> Could you help me ?
>
> Thanks
> ste
>
>
> ------------------------------------------------------------ ---------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See 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
>
>

--0050450140ee1c2243047fc01ed1
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

RewriteRule doesn't work with the query part or the URI thus will not w=
ork in your case. You need to try RewriteCond directive combined with Rewri=
teRule. Something like this maybe?

RewriteEngine On
RewriteCond %=
{QUERY_STRING} ^(filename=3Dmyfile.txt)$

RewriteRule =A0 .*=A0 - [E=3DFILENAME:%1]
Header set "Content-dispo=
sition" "attachment; filename=3D%{FILENAME}e" env=3DFILENAME=


I'm not sure though about the effect of the Header set directiv=
e, is it going to have a global effect afterwords or not?


Igor

On Wed, Feb 17, 2010 at 9:21 AM,=
Stefano Nichele < ail.com">stefano.nichele@gmail.com> wrote:
ss=3D"gmail_quote" style=3D"border-left: 1px solid rgb(204, 204, 204); marg=
in: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi All,

I would need some help with mod_rewrite :-( .

What I would need is to add an header to the response if the request contai=
ns a URL parameter and the value of that parameter should be used in that h=
eader.



Just =A0to clarify, if the url is:



/download/files/1ytreefecsw?filename=3Dmyfile.txt



I would like to return this file /download/files/1ytreefecsw setting in the=
response "Content-disposition" header with value myfile.txt:



"Content-disposition: attachment; filename=3Dmyfile.txt



I was able to do this thing checking a request header using:

=A0 =A0SetEnvIf x-filename "^(.+)$" FILENAME=3D$1

=A0 =A0Header set "Content-disposition" "attachment; filena=
me=3D%{FILENAME}e" env=3DFILENAME



but now i need to do similar thing using a parameter.



I understand that there is not a simple way to access to the query_string a=
nd actually this is not possible using SetEnvIf and it seems the right way =
=A0is using mod_rewrite .... but i don't find the solution.

At the moment i'm trying something like:



=A0 =A0RewriteEngine on

=A0 =A0RewriteRule =A0 ^(.*)filename=3D(.*)$ =A0$1 [E=3DFILENAME:$2]

=A0 =A0Header set "Content-disposition" "attachment; filena=
me=3D%{FILENAME}e" env=3DFILENAME



but it doesn't work =A0:-((



Could you help me ?



Thanks

ste





------------------------------------------------------------ ---------

The official User-To-User support forum of the Apache HTTP Server Project.<=
br>
See <URL: lank">http://httpd.apache.org/userslist.html> for more info.

To unsubscribe, e-mail: g" target=3D"_blank">users-unsubscribe@httpd.apache.org

=A0" =A0 from the digest: httpd.apache.org" target=3D"_blank">users-digest-unsubscribe@httpd.apache.o=
rg


For additional commands, e-mail: org" target=3D"_blank">users-help@httpd.apache.org






--0050450140ee1c2243047fc01ed1--

Re: handling parameter in query_string with mod_rewrite

am 17.02.2010 00:36:05 von Igor Cicimov

--000e0cd5c61c8b9649047fc0321f
Content-Type: text/plain; charset=ISO-8859-1

Sorry this should have been like this actually

RewriteEngine On
RewriteCond %{QUERY_STRING} ^filename=(myfile.txt)$
RewriteRule .* - [E=FILENAME:%1]

to set the FILENAME variable to myfile.txt value.

Igor

On Wed, Feb 17, 2010 at 10:30 AM, Igor Cicimov wrote:

> RewriteRule doesn't work with the query part or the URI thus will not work
> in your case. You need to try RewriteCond directive combined with
> RewriteRule. Something like this maybe?
>
> RewriteEngine On
> RewriteCond %{QUERY_STRING} ^(filename=myfile.txt)$
> RewriteRule .* - [E=FILENAME:%1]
>
> Header set "Content-disposition" "attachment; filename=%{FILENAME}e"
> env=FILENAME
>
> I'm not sure though about the effect of the Header set directive, is it
> going to have a global effect afterwords or not?
>
> Igor
>
>
> On Wed, Feb 17, 2010 at 9:21 AM, Stefano Nichele <
> stefano.nichele@gmail.com> wrote:
>
>> Hi All,
>> I would need some help with mod_rewrite :-( .
>> What I would need is to add an header to the response if the request
>> contains a URL parameter and the value of that parameter should be used in
>> that header.
>>
>> Just to clarify, if the url is:
>>
>> /download/files/1ytreefecsw?filename=myfile.txt
>>
>> I would like to return this file /download/files/1ytreefecsw setting in
>> the response "Content-disposition" header with value myfile.txt:
>>
>> "Content-disposition: attachment; filename=myfile.txt
>>
>> I was able to do this thing checking a request header using:
>> SetEnvIf x-filename "^(.+)$" FILENAME=$1
>> Header set "Content-disposition" "attachment; filename=%{FILENAME}e"
>> env=FILENAME
>>
>> but now i need to do similar thing using a parameter.
>>
>> I understand that there is not a simple way to access to the query_string
>> and actually this is not possible using SetEnvIf and it seems the right way
>> is using mod_rewrite .... but i don't find the solution.
>> At the moment i'm trying something like:
>>
>> RewriteEngine on
>> RewriteRule ^(.*)filename=(.*)$ $1 [E=FILENAME:$2]
>> Header set "Content-disposition" "attachment; filename=%{FILENAME}e"
>> env=FILENAME
>>
>> but it doesn't work :-((
>>
>> Could you help me ?
>>
>> Thanks
>> ste
>>
>>
>> ------------------------------------------------------------ ---------
>> The official User-To-User support forum of the Apache HTTP Server Project.
>> See 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
>>
>>
>

--000e0cd5c61c8b9649047fc0321f
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Sorry this should have been like this actually

RewriteEngine On
R=
ewriteCond %{QUERY_STRING} ^filename=3D(myfile.txt)$

RewriteRule =A0 .*=A0 - [E=3DFILENAME:%1]

to set the FILENAME variab=
le to myfile.txt value.

Igor

On W=
ed, Feb 17, 2010 at 10:30 AM, Igor Cicimov < "mailto:icicimov@gmail.com">icicimov@gmail.com> wrote:

204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">RewriteRule doesn=
't work with the query part or the URI thus will not work in your case.=
You need to try RewriteCond directive combined with RewriteRule. Something=
like this maybe?


RewriteEngine On
RewriteCond %{QUERY_STRING} ^(filename=3Dmyfile.txt=
)$

RewriteRule =A0 .*=A0 - [E=3DFILENAME:%1]

Header set &=
quot;Content-disposition" "attachment; filename=3D%{FILENAME}e&qu=
ot; env=3DFILENAME

I'm not sure though about the effect of=
the Header set directive, is it going to have a global effect afterwords o=
r not?



Igor


l_quote">On Wed, Feb 17, 2010 at 9:21 AM, Stefano Nichele ><stefano=
..nichele@gmail.com
>
wrote:

204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi All,

I would need some help with mod_rewrite :-( .

What I would need is to add an header to the response if the request contai=
ns a URL parameter and the value of that parameter should be used in that h=
eader.



Just =A0to clarify, if the url is:



/download/files/1ytreefecsw?filename=3Dmyfile.txt



I would like to return this file /download/files/1ytreefecsw setting in the=
response "Content-disposition" header with value myfile.txt:



"Content-disposition: attachment; filename=3Dmyfile.txt



I was able to do this thing checking a request header using:

=A0 =A0SetEnvIf x-filename "^(.+)$" FILENAME=3D$1

=A0 =A0Header set "Content-disposition" "attachment; filena=
me=3D%{FILENAME}e" env=3DFILENAME



but now i need to do similar thing using a parameter.



I understand that there is not a simple way to access to the query_string a=
nd actually this is not possible using SetEnvIf and it seems the right way =
=A0is using mod_rewrite .... but i don't find the solution.

At the moment i'm trying something like:



=A0 =A0RewriteEngine on

=A0 =A0RewriteRule =A0 ^(.*)filename=3D(.*)$ =A0$1 [E=3DFILENAME:$2]

=A0 =A0Header set "Content-disposition" "attachment; filena=
me=3D%{FILENAME}e" env=3DFILENAME



but it doesn't work =A0:-((



Could you help me ?



Thanks

ste





------------------------------------------------------------ ---------

The official User-To-User support forum of the Apache HTTP Server Project.<=
br>
See <URL: lank">http://httpd.apache.org/userslist.html> for more info.

To unsubscribe, e-mail: g" target=3D"_blank">users-unsubscribe@httpd.apache.org

=A0" =A0 from the digest: httpd.apache.org" target=3D"_blank">users-digest-unsubscribe@httpd.apache.o=
rg


For additional commands, e-mail: org" target=3D"_blank">users-help@httpd.apache.org








--000e0cd5c61c8b9649047fc0321f--

Re: handling parameter in query_string with mod_rewrite

am 17.02.2010 10:18:36 von Stefano Nichele

--------------000405040806030002070304
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Hi Igor,
maybe my issue was not fully clear but your suggestion puts me on the
right way .... thanks a lot !!

What I'm using now (and it seems working) is:

RewriteEngine on
RewriteCond %{QUERY_STRING} ^(.*)[\&|\?]*filename=([\w|\d|\.|\%|
]*)[\&]*(.*)$
RewriteRule .* - [E=FILENAME:%2]

Header set "Content-disposition" "attachment;
filename=%{FILENAME}e" env=FILENAME
UnsetEnv FILENAME

The main difference is that myfile.txt was just an example, ie, I
should be able to handle any value and that parameter in any position.
For instance:

/download/files/1ytreefecsw?filename=first.txt
/download/files/1ytreefecsw?param1=value1&filename=second.tx t¶m3=value3

Ste


On 17/02/2010 0.36, Igor Cicimov wrote:
> Sorry this should have been like this actually
>
> RewriteEngine On
> RewriteCond %{QUERY_STRING} ^filename=(myfile.txt)$
> RewriteRule .* - [E=FILENAME:%1]
>
> to set the FILENAME variable to myfile.txt value.
>
> Igor
>
> On Wed, Feb 17, 2010 at 10:30 AM, Igor Cicimov > > wrote:
>
> RewriteRule doesn't work with the query part or the URI thus will
> not work in your case. You need to try RewriteCond directive
> combined with RewriteRule. Something like this maybe?
>
> RewriteEngine On
> RewriteCond %{QUERY_STRING} ^(filename=myfile.txt)$
> RewriteRule .* - [E=FILENAME:%1]
>
> Header set "Content-disposition" "attachment;
> filename=%{FILENAME}e" env=FILENAME
>
> I'm not sure though about the effect of the Header set directive,
> is it going to have a global effect afterwords or not?
>
> Igor
>
>
> On Wed, Feb 17, 2010 at 9:21 AM, Stefano Nichele
> > wrote:
>
> Hi All,
> I would need some help with mod_rewrite :-( .
> What I would need is to add an header to the response if the
> request contains a URL parameter and the value of that
> parameter should be used in that header.
>
> Just to clarify, if the url is:
>
> /download/files/1ytreefecsw?filename=myfile.txt
>
> I would like to return this file /download/files/1ytreefecsw
> setting in the response "Content-disposition" header with
> value myfile.txt:
>
> "Content-disposition: attachment; filename=myfile.txt
>
> I was able to do this thing checking a request header using:
> SetEnvIf x-filename "^(.+)$" FILENAME=$1
> Header set "Content-disposition" "attachment;
> filename=%{FILENAME}e" env=FILENAME
>
> but now i need to do similar thing using a parameter.
>
> I understand that there is not a simple way to access to the
> query_string and actually this is not possible using SetEnvIf
> and it seems the right way is using mod_rewrite .... but i
> don't find the solution.
> At the moment i'm trying something like:
>
> RewriteEngine on
> RewriteRule ^(.*)filename=(.*)$ $1 [E=FILENAME:$2]
> Header set "Content-disposition" "attachment;
> filename=%{FILENAME}e" env=FILENAME
>
> but it doesn't work :-((
>
> Could you help me ?
>
> Thanks
> ste
>
>
> ------------------------------------------------------------ ---------
> The official User-To-User support forum of the Apache HTTP
> Server Project.
> See 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
>
>
>
>


--
Stefano Nichele

Funambol Chief Architect
Funambol :: Open Source Mobile Cloud Sync and Push Email


--------------000405040806030002070304
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit




http-equiv="Content-Type">


Hi Igor,

maybe my issue was not fully clear but your suggestion puts me on the
right way .... thanks a lot !!



What I'm using now (and it seems working) is:



    RewriteEngine on

    RewriteCond %{QUERY_STRING}
^(.*)[\&|\?]*filename=([\w|\d|\.|\%| ]*)[\&]*(.*)$

    RewriteRule   .*  - [E=FILENAME:%2]



    Header set "Content-disposition" "attachment;
filename=%{FILENAME}e" env=FILENAME

    UnsetEnv FILENAME



The main difference is that myfile.txt was just an example, ie,  I
should be able to handle any value and that parameter in any position.
For instance:



/download/files/1ytreefecsw?filename=first.txt

/download/files/1ytreefecsw?param1=value1&filename=secon d.txt&param3=value3



Ste





On 17/02/2010 0.36, Igor Cicimov wrote:
cite="mid:f89deef01002161536qbec90endbb49a5f0c07010f@mail.gm ail.com"
type="cite">Sorry this should have been like this actually



RewriteEngine On

RewriteCond %{QUERY_STRING} ^filename=(myfile.txt)$

RewriteRule   .*  - [E=FILENAME:%1]



to set the FILENAME variable to myfile.txt value.



Igor



On Wed, Feb 17, 2010 at 10:30 AM, Igor
Cicimov < href="mailto:icicimov@gmail.com">icicimov@gmail.com>
wrote:

style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">RewriteRule
doesn't work with the query part or the URI thus will not work in your
case. You need to try RewriteCond directive combined with RewriteRule.
Something like this maybe?



RewriteEngine On

RewriteCond %{QUERY_STRING} ^(filename=myfile.txt)$

RewriteRule   .*  - [E=FILENAME:%1]


Header set "Content-disposition" "attachment; filename=%{FILENAME}e"
env=FILENAME




I'm not sure though about the effect of the Header set directive, is it
going to have a global effect afterwords or not?




Igor






On Wed, Feb 17, 2010 at 9:21 AM, Stefano
Nichele < href="mailto:stefano.nichele@gmail.com" target="_blank">stefano.nichele@gmail.com>
wrote:

style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi All,

I would need some help with mod_rewrite :-( .

What I would need is to add an header to the response if the request
contains a URL parameter and the value of that parameter should be used
in that header.



Just  to clarify, if the url is:



/download/files/1ytreefecsw?filename=myfile.txt



I would like to return this file /download/files/1ytreefecsw setting in
the response "Content-disposition" header with value myfile.txt:



"Content-disposition: attachment; filename=myfile.txt



I was able to do this thing checking a request header using:

   SetEnvIf x-filename "^(.+)$" FILENAME=$1

   Header set "Content-disposition" "attachment; filename=%{FILENAME}e"
env=FILENAME



but now i need to do similar thing using a parameter.



I understand that there is not a simple way to access to the
query_string and actually this is not possible using SetEnvIf and it
seems the right way  is using mod_rewrite .... but i don't find the
solution.

At the moment i'm trying something like:



   RewriteEngine on

   RewriteRule   ^(.*)filename=(.*)$  $1 [E=FILENAME:$2]

   Header set "Content-disposition" "attachment; filename=%{FILENAME}e"
env=FILENAME



but it doesn't work  :-((



Could you help me ?



Thanks

ste





------------------------------------------------------------ ---------

The official User-To-User support forum of the Apache HTTP Server
Project.

See <URL: href="http://httpd.apache.org/userslist.html" target="_blank">http://httpd.apache.org/userslist.html>
for more info.

To unsubscribe, e-mail: href="mailto:users-unsubscribe@httpd.apache.org" target="_blank">users-unsubscribe@httpd.apache.org

 "   from the digest: href="mailto:users-digest-unsubscribe@httpd.apache.org" target="_blank">users-digest-unsubscribe@httpd.apache.org

For additional commands, e-mail: href="mailto:users-help@httpd.apache.org" target="_blank">users-help@httpd.apache.org


















-- 
Stefano Nichele

Funambol Chief Architect
Funambol :: Open Source Mobile Cloud Sync and Push Email




--------------000405040806030002070304--