Sunday, September 30, 2012

non-root SCRIPT_NAME, mod_wsgi and RewriteRule

I have my Django website and my static files deployed under the same
directory (i.e. no separate 'static' directory), according to the
following Apache RewriteRule:

RewriteEngine on
RewriteRule ^.*$ /django/$1 [QSA,PT,L]

WSGIScriptAlias /django/ /var/www/

My site-wide urlconf looks like this:

urlpatterns = patterns('',
url(r'^blog/', include('blog.urls')),
url(r'', include('home.urls')),

With my app-specific urlconf ('home.urls') is simply this:

urlpatterns = patterns('home.views',
url(r'^(?P<uri>[a-z0-9-]+)/?$', 'page_by_uri'),
url(r'^$', 'index'),

So when I visit my site I should see the index view (which it
does), and when I visit I should see the
page_by_uri('foo') view, *which it doesn't*. Instead, it shows the index
view. (And I thought it should give an error!)

Having surfed around a little bit, I reckon it's got something to do
with Django's handling of SCRIPT_NAME (which should be equal to the
mount point, in my case '/dj'). Various solutions are proposed,
generally involving adding the mount point to my urlconf (bad!) until I
tried it and it doesn't even work...

Basically, how in the name of all that is holy and sacred can I get this
to work?!

Thanks in advance

No comments:

Post a Comment