Loading...

Dreamhost, Django, and Site Statistics

July 10, 2007 Tagged as: django dreamhost python

I followed Jeff Croft's Howto to install Django with Dreamhost, my hosting provider. This works well, and, while I didn't follow his instructions to the letter, I followed it close enough to know how the underpinnings worked. I've gone through now three revisions of my software, each time, being careful not to step on my Django installation (which is trivial). As you can see from my site, it works well.

Today I ran into a snafu. Dreamhost uses Analog 6.0 to provide simple web statistics. I've been having a hard time implementing my Google Analytics middleware with Django, so I decided I'd use the Analog stuff for now. However, when I navigate to the statistics url page, the FCGI dispatcher I use with Django grabs the request, and handles it as a 404 error. After reading an entirely too much about Apache redirects, I finally figured it out. If you follow Jeff Croft's .htaccess instructions, your file should look like this:


RewriteEngine On
RewriteBase /
RewriteRule ^(media/.*)$ - [L]
RewriteRule ^(admin_media/.*)$ - [L]
RewriteRule ^(dispatch\.fcgi/.*)$ - [L]
RewriteRule ^(.*)$ dispatch.fcgi/$1 [L]

The trouble occurs because you must specify what url strings aren't handled by the dispatch.fcgi file, and everything else will be handled by it. So I added one line to the .htaccess file that would fix the Dreamhost stats for me, so it now looks like this:


RewriteEngine On
RewriteBase /
RewriteRule ^(media/.*)$ - [L]
RewriteRule ^(admin_media/.*)$ - [L]
RewriteRule ^(dispatch\.fcgi/.*)$ - [L]
RewriteCond %{REQUEST_URI} ^/stats/(.*)$ [OR]
RewriteRule ^(.*)$ dispatch.fcgi/$1 [L]

Thank goodness for stats! The result is the knowledge that The Iron Lion is growing very rapidly! Soon there will be more features here, and I'll also be releasing another tarball of the entire site.