id,summary,reporter,owner,description,type,status,component,version,severity,resolution,keywords,cc,stage,has_patch,needs_docs,needs_tests,needs_better_patch,easy,ui_ux 12464,Empty PATH_INFO causes blank SCRIPT_NAME,chrisw,Greg Wogan-Browne,"Take the following Apache config snippet: {{{ RewriteEngine On WSGIScriptAlias /project /django/project/bin/django.wsgi }}} This results in mod_rewrite setting the SCRIPT_URL environment variable. The code at http://code.djangoproject.com/browser/django/tags/releases/1.1.1/django/core/handlers/base.py#L204: {{{ script_url = environ.get('SCRIPT_URL', u'') if not script_url: script_url = environ.get('REDIRECT_URL', u'') if script_url: return force_unicode(script_url[:-len(environ.get('PATH_INFO', ''))]) return force_unicode(environ.get('SCRIPT_NAME', u'')) }}} ...behaves incorrectly when, in the above example, /project is requested from Apache. The problem is when PATH_INFO is empty, as it is in this case. Python has no notion of positive or negative zero (;-)) so we end up returning `script_url[:0]`. This results in `request.META['SCRIPT_NAME']`being set to `''`, which in turn results in urls being generated incorrectly. A workaround for this is to add the following rewrite rule before !WSGIScriptAlias: {{{ RewriteRule ^/project$ /project/ [R] }}} This bug is potentially related to #9435, but this is ticket describes a real world problem that I believe has bitten more people than just me... A solution for this could well just be to change the section to: {{{ if script_url: path_info = environ.get('PATH_INFO', '') if path_info: script_url = script_url[:-len(path_info)] return force_unicode(script_url) return force_unicode(environ.get('SCRIPT_NAME', u'')) }}} ...but I have no idea where to go about writing a test.",Bug,closed,HTTP handling,dev,Normal,duplicate,,Graham.Dumpleton@…,Accepted,1,0,0,1,0,0