Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Trying to setup django to take subdomains and use different settings file based on subdomain

dns is setup as wildcards

apache mod_vhost_alias sounded like good option, it did not work

SetEnv DJANGO_SETTINGS_MODULE site.settings.%1

gets this error

ImportError: Could not import settings 'site.settings.%1'

can mod_vhost_alias be made to work somehow? can rewrite module be used to pass along subdomain to django settings? is there any other way to pick up different settings files based on subdomain

share|improve this question

mod_rewrite's RewriteRule has a flag, E, that sets an environment variable. You could probably have a RewriteRule that matches everything and sets E=DJANGO_SETTINGS_MODULE:%{SERVER_NAME)

%0, %1 etc. from mod_vhost_alias only works in its own settings such as VirtualScriptAlias etc.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.