title: Django + apache: How can I create a server alias which invisibly redirects to my django app on the server?
body: <p>I am trying to figure out a how to forward a specific alias of a server to a specific django web app, and at the same time, keep the URL address bar in the user's browser to only show the server alias.  </p>
  
  <p>To be more specific: </p>
  
  <p>This is for an intranet project at my company.  We have a big linux server which does a lot of computational work, and it is also running apache to serve a variety of web pages and apps.  My current django app is running at:</p>
  
  <pre><code>http://deptserver.example.com/mydjangoapps/myapp
  </code></pre>
  
  <p>But, I would love it if my users could use this instead:</p>
  
  <pre><code>http://myapp.example.com/
  </code></pre>
  
  <p>(I already have the IT folks forwarding myapp.example.com to deptserver.example.com via a CNAME in the DNS)</p>
  
  <p>I can't break anything on the apache server, since it is serving critical stuff, but I do have the ability to add in things like a VirtualHost or some url rewriting rules, etc.</p>
  
  <p>This is my django setup in the apache httpd.conf file:</p>
  
  <pre><code>&lt;Location "/mydjangoapps"&gt;
      SetHandler python-program
      PythonHandler django.core.handlers.modpython
      SetEnv DJANGO_SETTINGS_MODULE mydjangopath.settings
      PythonOption django.root /mydjangoapps
      PythonPath "['/home/me/mydjangopath'] + sys.path"
      PythonDebug On
  &lt;/Location&gt;
  </code></pre>
  
  <p>And, this is in the sites-enabled default file (i.e. I can't break this part of the server):</p>
  
  <pre><code>&lt;VirtualHost *:80&gt;
          ServerAdmin webmaster@example.com
          DocumentRoot /var/www
          &lt;Directory /&gt;
                  Options FollowSymLinks
                  AllowOverride None
          &lt;/Directory&gt;
          &lt;Directory /var/www/&gt;
                  Options Indexes FollowSymLinks MultiViews
                  AllowOverride None
                  Order allow,deny
                  allow from all
          &lt;/Directory&gt;
  
          ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
          &lt;Directory "/usr/lib/cgi-bin"&gt;
                  AllowOverride None
                  Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                  Order allow,deny
                  Allow from all
          &lt;/Directory&gt;
  
          ErrorLog /var/log/apache2/error.log
  
          # Possible values include: debug, info, notice, warn, error, crit,
          # alert, emerg.
          LogLevel warn
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>In that above VirtualHost I've tried something like this using mod_rerwite:</p>
  
  <pre><code>RewriteEngine On
  RewriteCond %{HTTP_HOST} ^myapp\.example\.com
  RewriteRule ^(.*) mydjangoapps/myapp$1
  </code></pre>
  
  <p>Which doesn't work because it thinks that mydjangoapps/myapp is a file path and not a URL path, so it gives me a 400 error.  I wish that it would forward to a URL path instead.</p>
  
  <p>I have also tried this:</p>
  
  <pre><code>RewriteEngine On
  RewriteCond %{HTTP_HOST} ^myapp\.example\.com
  RewriteRule ^(.*) http://deptserver.example.com/mydjangoapps/myapp$1
  </code></pre>
  
  <p>Which just forwards the user to that long URL.</p>
  
  <p>These are the things I have thought about but haven't tried too much:
  virtualhost
  mod_rewrite
  alias
  proxy (?)
  port (putting my own apache server on a different port of the main server)</p>
  
  <p>What's the best way (or only way) to do this?</p>
  
  <p>Thanks!</p>