In a follow up to last night's post on setting up Django on WHM server, lets say you have a Django app you want to use on the main site, but you have additional code or apps(like a php forum) that you want to also use. After a little digging I beleive I've found the ideal configuration for this. There are 2 parts:
- Set up your django app's alias on a path other than the root of the site. In my setup I've put the django app on the /site path.
-
Modify your .htaccess in the root of the web site as follows:
# BEGIN Django
RewriteEngine On RewriteBase / RewriteRule "^$" "/site/$1" [QSA,PT,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule "^(.*)$" "/site/$1" [QSA,PT,L] # END Django
-
We're applying this to all files from th root up:
RewriteBase /
-
Replace an empty path with the path to the Django app located in /site/
RewriteRule "^$" "/site/" [QSA,PT,L]
-
This second rule only applies if the requested path is neither a file nor a directory, if so then it treats the path as /site/<your requested path>
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule "^(.*)$" "/site/$1" [QSA,PT,L]
- QSA (query string append) which appends the requested query string to the new path
- PT (passthrough) passes the originally requested path to the application rather than the modified one, this way Django can process the URLs as if it's in the root of the site rather than if it were aliased and no special parsing is needed to correct any redirects created dynamically in Django.
- L (last) simply means that if we've hit this rule, quit processing more.
Comments
Post a Comment