2

I have a Django site, working on mod_wsgi and Apache. (eg, example.com) I made a subdomain (eg, info.example.com) and want to point it to app in the existing project. Is it possible, that I have one urls.py file, and example.com/info and info.example.com point to the same view in Django project (without duplicating the whole project in different directory)?

If so, how can I do it? Currently the example.com virtalhost config for the existing project looks like this:

<VirtualHost 12.34.56.78:80>
   ServerName example.com
   ServerAlias www.example.com

   DocumentRoot /srv/www/Example/Pub_html

   WSGIScriptAlias / /srv/www/Example/example.wsgi
   <Directory /srv/www/Example/Example>
      Order allow,deny
      Allow from all
   </Directory>

   Alias /robots.txt /srv/www/Example/robots.txt
   Alias /favicon.ico /srv/www/Example/favicon.ico
   ....
</VirtualHost>

Thanks in advance!

UPDATE: I did a quick fix here by creating another Django project which shares database tables and template folder with the existing one. It works, but it's not really DRY :)

1
  • You probably want to add a RewriteRule, which would internally transform the info.example.com to example.com/info. Those are notoriously difficult to write, though. Commented Apr 13, 2011 at 13:41

1 Answer 1

1

I'd do this with a reverse proxy, I reckon. If you have mod_proxy and mod_proxy_html available, try something like this:

<VirtualHost 12.34.56.78:80>
    ServerName info.example.com

    ProxyPass       /  http://example.com/info

    SetOutputFilter proxy-html
    <Location />
        ProxyPassReverse /info/
        ProxyHTMLURLMap /info/ /
    </Location>
    ProxyHTMLURLMap http://example.com/info /
</VirtualHost>

the details may not be quite right, so let me know if you can't get it to work.

Sign up to request clarification or add additional context in comments.

1 Comment

I got it working with just the ProxyPass line. With the full file it was throwing error 330 in google chrome and I had [error] proxy: ap_get_scoreboard_lb(1) failed in child 14565 for worker proxy:reverse; [error] proxy: ap_get_scoreboard_lb(0) failed in child 14565 for worker example.com/info

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.