Sorry for the newbie apache question. I'm wondering if it's possible to set up the following non-conventional apache virtualhost (for a Django app):

-- If a file exists in the DocumentRoot (/var/www) it will be shown. So if /var/www/foo.html exists, then it can be seen at www.example.com/foo.html.

-- If file does not exist, it is served via a virtualhost. I'm using mod_wsgi with a WSGIScriptAlias directive that points to a Django app. So if there is no /var/www/bar.html, www.example.com/bar.html will be passed to the Django app, which may or may not be a 404 error.

One option is to create an Alias for each individual file/directory, but people want to be able to post a file without adding an alias, and we want to keep the above URL structure for legacy reasons.

Simplified Virtualhost is:

<VirtualHost *:80>
  ServerName www.example.com
  DocumentRoot /var/www

  WSGIScriptAlias / /path/to/django.wsgi
  <Directory /path/to/app>
    Order allow,deny
    Allow from all

  Alias /hi.html /var/www/hi.html

The goal is to have www.example.com/hi.html work as above, without the Alias line


Documentation on mod_wsgi site on how to do this is at:


Use combination of AddHandler and mod_rewrite. Don't use WSGIScriptAlias.

| improve this answer | |
  • Yup, that's it. (For others curious, the thread I posted above was also helpful.) You guys are awesome. – Brett Thomas Nov 22 '11 at 17:09

Using apache I do not believe this is possible, using nGinx however.

<The rest of your server {} config above>
location @fallback {
     proxy_pass http://<your_uwscgi_server>:<port>;
error_page 404 = @fallback;
<any futher server {} configuration>

I may be wrong, for instance I do not know enough about EnvIF in apache and ether this could be used to provide similar functionality.

| improve this answer | |
  • 2
    isn't try_files intended for this? – Tobi Nov 14 '11 at 17:22
  • It is possible with Apache and is done all the time with PHP sites. How to do it with mod_wsgi is covered in mod_wsgi documentation. – Graham Dumpleton Nov 15 '11 at 0:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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