Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1004155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:05:24+00:00 2026-05-16T08:05:24+00:00

I have a Django application being served of (say) example.com . It contains a

  • 0

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 request object passed to my view methods. I then do the whole thing inside my application logic.
  • The other is to use Apache mod_rewrite to 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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T08:05:25+00:00Added an answer on May 16, 2026 at 8:05 am

    For this answer I’m assuming that you’re willing to do a mod_rewrite for each subdomain. I don’t think this will work for any subdomain (i.e. the x you mention).

    This will strip out the leading /skill/ so that your app will continue to work:

    RewriteCond %{HTTP_HOST} !www.example.com$ [NC]
    RewriteCond %{HTTP_HOST} ^(www.)?skill.example.com [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule (/skill/)?(.*) /skill/$2
    

    Update

    Okay, so you want to strip out the leading part of the URL in the link itself.

    Basically, that means you have to write a custom tag to replace the {% url %} tag, something like this:

    import re
    from django.template import Library
    from django.template.defaulttags import URLNode, url
    
    register = Library()
    
    class SubdomainURLNode(URLNode):
        def render(self, context):
            domain = context['request'].get_host()
            subdomain = re.sub(r'^www\.','',domain).split('.')[0]
            path = super(SubdomainURLNode, self).render(context)
            return re.sub(r'^/%s/' % subdomain, '/', path)
    
    @register.tag
    def subdomainurl(parser, token, node_cls=SubdomainURLNode):
        """Just like {% url %} but checks for a subdomain."""
        node_instance = url(parser, token)
        return node_cls(view_name=node_instance.view_name,
            args=node_instance.args,
            kwargs=node_instance.kwargs,
            asvar=node_instance.asvar)
    

    I’ve tested this on my server and it appears to work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a a django application which is being served from apache/mod_wsgi under www.mysite.com/mysite
I have set up a Django application that uses images. I think I have
I'm working on a blog application in Django. Naturally, I have models set up
Do the major web application frameworks (Rails, Django, etc) have libraries that provide functionality
I have worked a bit with Django and I quite like its project/applications model
Does Django have any template tags to generate common HTML markup? For example, I
I have a Django model with a large number of fields and 20000+ table
I have a django application using mod_python, fairly typical configuration except that media files
In a django application I am working on, I have just added the ability
I have a many-to-many relationship in my django application where I use the add

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.