[mod_python] Getting query parameters when there is RewriteRule

Graham Dumpleton graham.dumpleton at gmail.com
Wed Apr 25 23:05:00 EDT 2007


On 26/04/07, sliderw hotmail <sliderw at hotmail.com> wrote:
> In httpd.conf, I have:
>
> RewriteRule ^/dl/([^/\?]+)/([^/\?]+)/? /dl/myhandler.py?a=$1&b=$2 [PT,L]
>
> and:
>
> Alias /dl/ "/some/path/"
> <Directory "/some/path/">
>   ... mod_python stuff here for myhandler ...
> </Directory>
>
> myhandler gets the query parameters using qp =
> req.parsed_uri[apache.URI_QUERY]. If I go to
> http://www.mysite.com/dl/myhandler.py?a=1&b=2, qp is "a=1&b=2", as expected.
> On the other hand, if I go to http://www.mysite.com/dl/1/2/, qp is None, but
> I expect qp is "a=1&b=2". How can I make this work?

Have you enabled debug in mod_rewrite and looked at the rewrite log to
verify what that your rule matches and is getting rewritten to what
you expect it to? What does it show?

What is the 'mod_python stuff here for myhandler' which you are using?

Have you tried using 'req.args' instead of getting it out of req.parsed_uri?

There is possibly a better way of doing this which avoids mod_rewrite
altogether but will have to think about it first before I suggest some
code to actually try. In short though it involves using a fixuphandler
to trigger mod_python instead of the Apache configuration. One can be
explicit about handler you then want executed and pass what you are
passing through as args as attributes stored against the request
object. Avoids having to do form args processing in actual response
handler.

Graham


More information about the Mod_python mailing list