Apache virtualhost - only apply script if file does not exist in document root
Posted
by
Brett Thomas
on Server Fault
See other posts from Server Fault
or by Brett Thomas
Published on 2011-11-14T16:28:11Z
Indexed on
2011/11/14
17:54 UTC
Read the original article
Hit count: 373
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
</Directory>
Alias /hi.html /var/www/hi.html
</VirtualHost>
The goal is to have www.example.com/hi.html work as above, without the Alias line
© Server Fault or respective owner