moving from mod_python + django to mod_wsgi _+ django issue

14 views
Skip to first unread message

JSL

unread,
Oct 12, 2009, 3:19:40 PM10/12/09
to modwsgi
Hi, i'm switching my mod_python apache setup to use mod_wsgi using
django as the framework. All was working well until except it seems
for one part. I have a redirect function which accepts another url
such as

/redirect/http://www.google.com

this worked fine with mod_python, but for some reason with mod_wsgi
the 2 slashes get squashed to one (in fact any number get squashed)

Is there something i've missed?

Thanks

Graham Dumpleton

unread,
Oct 12, 2009, 5:50:24 PM10/12/09
to mod...@googlegroups.com
2009/10/13 JSL <te...@pricegoblin.co.uk>:

That is how Apache works. If it worked on mod_python before then
Django must have been side stepping the normal variables a Python web
applications should use, especially WSGI applications, and using the
unescaped REQUEST_URI variable. One shouldn't as a rule rely on
REQUEST_URI.

Also make sure you read this discussion:

http://groups.google.com/group/python-web-sig/browse_frm/thread/2003e1c1ecce27b2

as it talks about this very issue and how you can work around it by
using custom encoding of URL information.

Graham

JSL

unread,
Oct 20, 2009, 4:51:01 PM10/20/09
to modwsgi


On Oct 12, 10:50 pm, Graham Dumpleton <graham.dumple...@gmail.com>
wrote:
> 2009/10/13 JSL <t...@pricegoblin.co.uk>:
>
>
>
> > Hi, i'm switching my mod_python apache setup to use mod_wsgi using
> > django as the framework. All was working well until except it seems
> > for one part. I have a redirect function which accepts another url
> > such as
>
> > /redirect/http://www.google.com
>
> > this worked fine with mod_python, but for some reason with mod_wsgi
> > the 2 slashes get squashed to one (in fact any number get squashed)
>
> > Is there something i've missed?
>
> That is how Apache works. If it worked on mod_python before then
> Django must have been side stepping the normal variables a Python web
> applications should use, especially WSGI applications, and using the
> unescaped REQUEST_URI variable. One shouldn't as a rule rely on
> REQUEST_URI.
>
> Also make sure you read this discussion:
>
>  http://groups.google.com/group/python-web-sig/browse_frm/thread/2003e...
>
> as it talks about this very issue and how you can work around it by
> using custom encoding of URL information.

Hi, thanks for the answer, after some digging it appears that
mod_rewrite strips out the double slashes (googling around didn't
point me in the direction of where or why - if anyone knows so i could
turn it off, i'd be grateful - it looks as though it treats it as a
file name in a subrequest).
When it does this, the django base handler creates calculates the
script_name variable as being the first x characters where x is the
number of characters removed from the rewritten url.
I've fixed it by setting FORCE_SCRIPT_NAME to the empty string

Thanks

JOHN

Graham Dumpleton

unread,
Oct 20, 2009, 10:38:05 PM10/20/09
to mod...@googlegroups.com
2009/10/21 JSL <te...@pricegoblin.co.uk>:
Duplicated slashes get stripped even if mod_rewrite is not used so
isn't tied specifically to that but occurs at a lower level with the
URL mapper of Apache.

All I can suggest is you have a look at the effect of setting
AllowEncodedSlashes. See:

http://httpd.apache.org/docs/2.2/mod/core.html#allowencodedslashes

You can't use '//', but if that is encoded as '%2F%2F', then Apache
will leave it alone and possibly can be recovered within the
application.

I did play with this a while back, but I can't remember what I worked
out about was and wasn't possible.

Graham
Reply all
Reply to author
Forward
0 new messages