I have a Django application being served of (say) example.com. It contains a number of sub-applications (say) strength, speed and skill. The URL scheme is something like http://example.com/strength, http://example.com/speed and http://example.com/skill. This is how I run my dev server (using runserver) and there are no problems whatsoever.
Now, during deployment, I need to have subdomains that map to these sub-applications. More specifically, I want http://x.example.com to map to http://example.com/x (for the above values of x) and then processing can go on.
I googled a little bit and found two ways of doing this.
- One is to get some middleware to get the subdomain part of the URL and keep it inside the
requestobject passed to my view methods. I then do the whole thing inside my application logic. - The other is to use Apache
mod_rewriteto do the above URL translation and then let my app run as usual.
I chose the latter since it looked neater and I thought I wouldn't have to include deployment specific code inside my core application.
Now, I'm bitten by a problem which I can't really find a way out of. Inside the skill application, I have a named url skill_home. It's http://example.com/skill. However, once I deploy, the skill_home URL becomes http://skill.example.com/skill. Django appends the /skill to the top level domain and this is what I get. If I do a GET on this URL, mod_rewrite changes it to http://skill.example.com/skill/skill and it doesn't work.
My mod_rewrite snippets look like this
RewriteCond %{HTTP_HOST} !www.example.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www.)?skill.example.com [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) /skill/$1
How do I fix this neatly?