Reprocessed, by Matt Patterson

Something approaching a weblog

Setting up MT 3.1's dynamic publishing with an Apache virtual host config

The suggested setup routine for MT 3.1's dynamic publishing gives instructions for use with .htaccess files. If, like me, you've got root access to some variety of unix box then you might well want to do your setup using an apache config file and not a .htaccess file: The performance of mod_rewrite processing rewrite rules in a config file is much better than rules in a .htaccess file.

What I did was to copy the rewrite rules block from Six Apart's dynamic publishing setup guide and use it inside my <VirtualHost> directive. I removed the last <IfModule> statement, because (since it's my server) I know that I do have mod_rewrite enabled. after restarting Apache I was able to get to my master index page fine.

However, the RewriteCond tests which were supposed to allow files and directories on the filesystem to pass through the URL rewriting weren't working: references to my stylesheets were 404ing.

After a bit of digging I figured out that the %{REQUEST_FILENAME} environment variable which is supposed to expand to the full filesystem path was only expanding to the full path from the virtual host's document root. I'm assuming that this difference is because the processing of rewrite rules at the .htaccess stage is very different from the processing that happens with rewrite rules in a config file, mostly because a lot of processing work has been done by apache by the time it gets to processing .htaccess files, and it has to recreate some of the environment needed for mod_rewrite using smoke and mirrors. There are plenty of details at the apache site here and here, but I'm afraid they're all pretty baffling.

Once I'd figured that out, I applied a corrective, in the form of the DOCUMENT_ROOT environment variable, which contained the missing information. My RewriteCond lines now work fine. They look like this:

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f

In case you're wondering, my server is a bytemark hosted virtual debian box, which is v. good & v. cheap, at only 15 quid a month. Bytemark are lovely people with a very good product: highly reccommended.

Not forgetting:

This page is: