You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Tony VanScoy <tv...@gmail.com> on 2005/08/17 20:45:14 UTC

[users@httpd] RewriteMap and sending more then 1 var

Thanks to the help of a number of people here. I've gotten RewriteMap
to work like a charm.

My question is about the variables being sent to the processing
program. Right now I'm using syntax like the following line ...

RewriteMap pdfFile prg:/home/user/getPDF.php

.. and I use that program to map file ID's to actual pdf filenames like such ...

RewriteCond %{QUERY_STRING} ^pdfId\=(\d+)$
RewriteRule ^/getpdf\.php$ /pdf/${pdfFile:%1}? [R,L,T=application/pdf]

.. works great. My question is about sending more then just 1
backreference to the map program. In this case, I'm sending %1. Can I
add to that? What if i wanted to also send the  HTTP_REFERER, or the 
REMOTE_HOST? These values would be great since I use the mapping
program to log the downloads to a database.

Would something like this work?

RewriteRule ^/getpdf\.php$
/pdf/${pdfFile:"%1|%{HTTP_REFERER}|%{REMOTE_HOST}"}?
[R,L,T=application/pdf]

I could just make one long string to be sent, with the values
separated by a pipe, where my mapping program could parse through and
get each individual value. I'm sure you know what I'm looking for at
this point and time, so any feedback on ways to do this would be
appreciated.

Thanks.

---------------------------------------------------------------------
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] RewriteMap and sending more then 1 var

Posted by Tony VanScoy <tv...@gmail.com>.
> Have you tried it?  What happened?

It worked after a few modifications

> Your idea is basically fine, except you should pick a character other than
> |, because that character is special in a rewritemap (used to
> designate a default value).  (Perhaps it doesn't matter if it is in
> quotes; I've never tried this myself.)

The quotes are passed along with the values so I didn't use them.
Here's what works

RewriteRule ^/getpdf\.php$
/pdf/${pdfFile:"%1_%{HTTP_REFERER}_%{REMOTE_HOST}"}?
[R,L,T=application/pdf]

> But you worry me a little when you talk about all the stuff you are
> doing in your RewriteMap.  These programs should be extremly simple
> because they run as root, and they are a choke point in that only one
> request at a time can be processed through the RewriteMap.

My mapping program only makes two database queries, one to get the
filename, and a second query to log the download. By default i have it
sending back "NULL\n". That value only gets changed if both queries
execute without error. I'm using @ to prevent any error output.

Thanks for your help.

---------------------------------------------------------------------
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] RewriteMap and sending more then 1 var

Posted by Joshua Slive <js...@gmail.com>.
On 8/17/05, Tony VanScoy <tv...@gmail.com> wrote:
> .. works great. My question is about sending more then just 1
> backreference to the map program. In this case, I'm sending %1. Can I
> add to that? What if i wanted to also send the  HTTP_REFERER, or the
> REMOTE_HOST? These values would be great since I use the mapping
> program to log the downloads to a database.
> 
> Would something like this work?

Have you tried it?  What happened? 

> 
> RewriteRule ^/getpdf\.php$
> /pdf/${pdfFile:"%1|%{HTTP_REFERER}|%{REMOTE_HOST}"}?
> [R,L,T=application/pdf]
> 
> I could just make one long string to be sent, with the values
> separated by a pipe, where my mapping program could parse through and
> get each individual value. I'm sure you know what I'm looking for at
> this point and time, so any feedback on ways to do this would be
> appreciated.

Your idea is basically fine, except you should pick a character other than 
|, because that character is special in a rewritemap (used to
designate a default value).  (Perhaps it doesn't matter if it is in
quotes; I've never tried this myself.)

But you worry me a little when you talk about all the stuff you are
doing in your RewriteMap.  These programs should be extremly simple
because they run as root, and they are a choke point in that only one
request at a time can be processed through the RewriteMap.

Joshua.

---------------------------------------------------------------------
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