October 6, 2003
Apache is Awesome (Exploring Directives)
Have been doing a bit with Apache recently on several different sites.
It started with a desire to move a site away from page-based URLs (ie switching /product/product1.php to /product/1). I've heard of this URL paradigm referred to as user-friendly or resource-based, but that's besides the point. It's a good thing to do and Apache helped me to do it. I used an AliasMatch directive, which was the simplest because it involved no changing on the pages (which are pregenerated):
AliasMatch ^/product/(.+) /home/www/products/product$1.phpAdding this directive enables us to use the new URLs while still supporting the old. In time, once internal and search indexes point to the new URLs we'll be free to undergo a code rewrite/refactoring project that may change all the underlying pages, but not the resource-based URLs.
A few days later I was setting up a resource machine which does a slew of things, including hosting a bug tracking system, grabbing and crunching Apache logs from production servers, serving collection of static pages. Decided to make a common navigation across 4 virtual domains, using PHPs auto_prepend_file in the php.ini config file. Easy way to get same nav across the top of every page, even across virtual domains. Cool stuff.
But wait, our bug tracking system, Anthill, is frame-based with it's own nav and looks quite odd with the prepended navigation. Makes sense when logged in to Anthill to not have the prepend. Piece of cake. In the virtual host directive I can use a php_var directive which allows me to set auto_prepend_file none, so for this virtual domain the prepend is ignored. Awesome.
Also, a number of the domains have changed (with our recent name change), stick in a few RewriteRule directives and everyone is getting to the right place.
Apache core directives, although well-documented and fairly simple to implement, deserve more attention.
Posted by mike at October 6, 2003 11:17 PM