title: django inner redirects
body: <p>I have one project that in my own development computer (uses mod_wsgi to serve the project) caused no problems. In live server (uses mod_fastcgi) it generates 500 though. </p>
  
  <p>my url conf is like this:</p>
  
  <pre><code># -*- coding: utf-8 -*-
  from django.conf.urls.defaults import *
  
  # Uncomment the next two lines to enable the admin:
  from django.contrib import admin
  admin.autodiscover()
  
  urlpatterns = patterns('',
        url(r'^admin/', include(admin.site.urls)),
        url(r'^', include('jalka.game.urls')),
  )
  </code></pre>
  
  <p>and</p>
  
  <pre><code># -*- coding: utf-8 -*-
  from django.conf.urls.defaults import *
  
  from django.contrib.auth import views as auth_views
  
  urlpatterns = patterns('jalka.game.views',
        url(r'^$',
              view = 'front',
              name = 'front',),
        url(r'^ennusta/(?P&lt;game_id&gt;\d+)/$',
              view = 'ennusta',
              name = 'ennusta',),
        url(r'^login/$',
              auth_views.login,
              {'template_name': 'game/login.html'},
              name='auth_login'),
        url(r'^logout/$',
              auth_views.logout,
              {'template_name': 'game/logout.html'},
              name='auth_logout'),
        url(r'^arvuta/$',
              view = 'arvuta',
              name = 'arvuta',),            
  )
  </code></pre>
  
  <p>and .htaccess is like that:</p>
  
  <pre><code>Options +FollowSymLinks 
  RewriteEngine on
  RewriteOptions MaxRedirects=10
  # RewriteCond %{HTTP_HOST} . 
  RewriteCond %{HTTP_HOST} ^www\.domain\.com
  RewriteRule (.*) http://domain.com/$1 [R=301,L]
  
  AddHandler fastcgi-script .fcgi
  
  RewriteCond %{HTTP_HOST} ^jalka\.domain\.com$ [NC]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*) cgi-bin/fifa2010.fcgi/$1 [QSA,L]
  
  RewriteCond %{HTTP_HOST} ^subdomain\.otherdomain\.eu$ [NC]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*) cgi-bin/django.fcgi/$1 [QSA,L]
  </code></pre>
  
  <p>Notice, that i have also other project set up with same .htaccess and that one is running just fine with more complex urls and views</p>
  
  <p>fifa2010.fcgi:</p>
  
  <pre><code>#!/usr/local/bin/python
  # -*- coding: utf-8 -*-
  import sys, os
  
  DOMAIN = "domain.com"
  APPNAME = "jalka"
  
  PREFIX = "/www/apache/domains/www.%s" % (DOMAIN,)
  
  # Add a custom Python path.
  sys.path.insert(0, os.path.join(PREFIX, "htdocs/django/Django-1.2.1"))
  sys.path.insert(0, os.path.join(PREFIX, "htdocs"))
  sys.path.insert(0, os.path.join(PREFIX, "htdocs/jalka"))
  
  
  # Switch to the directory of your project. (Optional.)
  os.chdir(os.path.join(PREFIX, "htdocs", APPNAME))
  
  # Set the DJANGO_SETTINGS_MODULE environment variable.
  os.environ['DJANGO_SETTINGS_MODULE'] = "%s.settings" % (APPNAME,)
  
  from django.core.servers.fastcgi import runfastcgi
  runfastcgi(method="threaded", daemonize="false")
  </code></pre>
  
  <p>Alan</p>
  
  <p>EDIT:I increased maximum redirects and got different kind of error:[Wed Jun  9 15:11:46 2010] [error] [client 84.50.104.242] (63)File name too long: access to /www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/ failed</p>
  
  <p>it looks like it keeps redirecting back to itself, but as to why - i have no idea.</p>
  
  <p>Edit2- Solved!
  In the end, when i changed my .htaccess to this it started working:</p>
  
  <pre><code>RewriteCond %{HTTP_HOST} ^jalka\.domain\.com$ [NC]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*) /cgi-bin/fifa2010.fcgi [QSA,L]
  
  RewriteCond %{HTTP_HOST} ^subdomain\.otherdomain\.eu$ [NC]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*) cgi-bin/django.fcgi/$1 [QSA,L]
  </code></pre>