title: Run Django with URL prefix ("subdirectory") - App works, but URLs broken?
body: <p>Below are the relevant configuration files, also at <a href="http://dpaste.com/97213/" rel="noreferrer">http://dpaste.com/97213/</a> .</p>
  
  <p>The apache config is currently working, because accessing 'example.com/' shows me the index.html file I have placed at the document root. </p>
  
  <p>I'd like to serve Django/apps at the prefix '/d', so 'example.com/d/' would load the default app, 'example.com/d/app3' would load another, as configured in urls.py. </p>
  
  <p>Serving Django, I'm using the suggested mod_wsgi, on Linux. </p>
  
  <p>Currently, I can access the Ticket app at 'example.com/d', but when the @login_required decorator tries to send me to the login page, I get sent to 'example.com/accounts/login', rather than the expected 'example.com/d/accounts/login'. </p>
  
  <p>Since the default app loads correctly, I'm not sure what <em>I'm</em> doing wrong here, or if this is a bug in Django when generating the urls. </p>
  
  <p>Any suggestions?</p>
  
  <p><strong>EDIT:</strong>
  As a note, if I change the apache config line: 
      WSGIScriptAlias /d /home/blah/django_projects/Tickets/apache/django.wsgi
  to
      WSGIScriptAlias / /home/blah/django_projects/Tickets/apache/django.wsgi
  The application, commenting, and logging in all work fine. Even going to 'example.com/admin' loads the admin, although I've left the admin media broken, so no stylesheets are loaded. </p>
  
  <p>--- Configs Follow: </p>
  
  <pre><code>#
  # /home/blah/django_projects/Ticket/urls.py
  #
  from django.conf.urls.defaults import *
  from django.contrib import admin
  admin.autodiscover()
  
  urlpatterns = patterns('',
      (r'^', include('ticket.urls')),
      (r'^admin/', include(admin.site.urls)),
      (r'^comments/', include('django.contrib.comments.urls')),
  )
  
  
  #
  # /home/blah/django_projects/Ticket/apache/django.wsgi
  #
  import os, sys
  
  sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..')
  
  sys.path.append('/home/blah/django_projects')
  sys.path.append('/home/blah/django_projects/Tickets')
  
  os.environ['DJANGO_SETTINGS_MODULE'] = 'Tickets.settings'
  
  import django.core.handlers.wsgi
  
  application = django.core.handlers.wsgi.WSGIHandler()
  
  
  #
  # /etc/apache2/sites-available/django_tickets_wsgi (apache conf)
  #
  NameVirtualHost *
  &lt;VirtualHost *&gt;  
  
      Alias /media /home/blah/django_projects/Tickets/media
  
  
      WSGIScriptAlias /d /home/blah/django_projects/Tickets/apache/django.wsgi
      WSGIDaemonProcess exmaple_com user=blah group=blah processes=1 threads=10
      WSGIProcessGroup example_com
  
      ServerAdmin localhost@example.com
      ServerName example.com
  
      DocumentRoot /var/www/
  
      &lt;Directory /var/www/&gt;
          Options -Indexes FollowSymLinks -MultiViews -Includes 
          AllowOverride None
          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
  
      CustomLog /var/log/apache2/access.log combined
      ServerSignature Off
  
  &lt;/VirtualHost&gt;
  </code></pre>