Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a Django app that handles "/admin/" and "/myapp/". All the other requests should be handled by Apache.

I've tried using LocationMatch but then I'd have to write a negative regex. I've tried WSGIScriptAlias with the /admin/ prefix but then the wsgi_handler receives the request with the /admin/ part cut off.

Is there a cleaner way to make mod_wsgi only handle certain requests?

share|improve this question


WSGIScriptAliasMatch ^/(admin|myapp) /some/path/django.wsgi/$1

This should preserve SCRIPT_NAME as matching root of web site so that still works for entries starting with admin and myapp.

share|improve this answer

Just using an alias in my apache configuration has always worked for me:

  Alias /media /sites/
  <Location /media>
    Order allow,deny
    Allow from all

It gets processed before mod_wsgi get near it.

From the django book

If you deploy Django at a subdirectory — that is, somewhere deeper that “/” — Django won’t trim the URL prefix off of your URLpatterns. So, if your Apache config looks like:

<Location "/mysite/">
    SetHandler python-program
    PythonHandler django.core.handlers.modpython
    SetEnv DJANGO_SETTINGS_MODULE mysite.settings
    PythonDebug On

The all your URL patterns will need to start with "/mysite/". For this reason we usually recommend deploying Django at the root of your domain or virtual host.

share|improve this answer
For media this works because it is a subpath. But what if I want to let the root "/" be handled by apache, and only certain URLs (/admin/, /myapp/) by mod_wsgi? – Frederik Jun 3 '10 at 16:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.