Web

Creative Commons License
Update: This is a good exaple of going in the wrong direction and completely overthinking a problem - the solution is simply to add an .htaccess file into the mint directory with the following:
<IfModule mod_rewrite.c>
  RewriteEngine On
</IfModule>
I'll leave this article here though as an example of modifying symfony's .htaccess rules to exclude certain requests, hopefully it will help someone solve something related - for instance with a simple modification (change /mint/ to /server-status/) I used the same rules below to enable Apache's mod_status on a symfony site.

Mint on Symfony

Shaun Inman's Mint (www.haveamint.com) is an excellent tracking package providing a high-level overview of site traffic and referrals. It doesn't give the drill-down detail of something like urchin/google analytics but I find that I usually don't need that much detail - I just want a general idea of how many people are hitting my site, what they are hitting, and where they are coming from. Mint also has a reasonably active user/developer community around it which has resulted in a variety of plugins (called 'Peppers') which allow you to tailor the stats it provides to your needs. For $30/site I've found it to be a vital tool for many of the sites I develop.

Lately I'm doing a lot of my web development in Symfony, a great open source web framework for php5. As I use Symfony more and more I suppose it was inevitable that I'd eventually want to deploy Mint on a site built in Symfony - and naturally there were complications.

Symfony uses a single front controller which processes all incoming site requests and routes them to appropriate modules based on custom routing rules. An .htaccess file is used to redirect all requests to the controller except for two situations - requests for files with an extension (images and static files - .jpg, .html, etc) and files that have been cached. Unfortunately these default routing rules prevent Mint from working properly...

The problem is the javascript which Mint uses on each page for tracking purposes calls the Mint application directory without an explicit call to the index.php file - probably to avoid revealing the use of php for security reasons. Thus all calls made to or by Mint get caught in the Symfony routing rules and result in a 404.

In the mint troubleshooting forum I came across a link to John Topley's post about installing mint on his Rails machine - it appears that Rails uses .htaccess in a similar manner to Symfony. While his Rails solution doesn't work directly in Symfony it got me pointed in the right direction and with a little tweaking I've got it working properly with now.

The important part is a single condition taken from Topley's solution:

# Don't redirect requests to /mint
RewriteCond %{REQUEST_URI} !^/mint/(.*)$
It basically just says that if the url is /mint/something to skip the next rule. Topley's Rails solution includes several other components, but it turns out we just need that one condition for Symfony. The tricky part is where we use it - we actually need it in two places (in red):
Options +FollowSymLinks +ExecCGI

<IfModule mod_rewrite.c>
  RewriteEngine On
    
  # we skip all files with .something
  RewriteCond %{REQUEST_URI} \..+$
  RewriteCond %{REQUEST_URI} !\.html$
  RewriteRule .* - [L]
    
  # we check if the .html version is here (caching)
  RewriteRule ^$ index.html [QSA]
  ## don't add .html to /mint requests
  RewriteCond %{REQUEST_URI} !^/mint/(.*)$
  RewriteRule ^([^.]+)$ $1.html [QSA]
  RewriteCond %{REQUEST_FILENAME} !-f
  
  ## Don't redirect requests to /mint
  RewriteCond %{REQUEST_URI} !^/mint/(.*)$
  # no, so we redirect to our front web controller
  RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>

# big crash from our front web controller
ErrorDocument 500 "<h2>Application error</h2>
symfony application failed to start properly"

The first place we use it is to avoid adding .html to the request - this is done as part of the check for a cached version of the requested file. Once that rule is skipped we pass to the final rule which would redirect to our controller - so we throw the same condition in again so that it doesn't redirect Mint requests.

That's it - simple once you know what to do, and probably simple if you are an .htaccess master. With luck this will save some time for others like me who do too many things to master any one...