In an effort to make the software that I write for $dayjob a bit more pleasing on the eye URL-wise, I started converting my code to use what is commonly called SEF (Search Engine Friendly) URLs. Not that a search engine will ever hit the administrative interface mind you. I decided to use Apache’s mod_rewrite functionality to achieve this, translating the ‘clean’ URLs into the URLs that my code expects.
I tested it for several days on my Gentoo / Apache 2 / PHP 5 development box, and all was well. The only odd thing was that a URL that looked like
required a rewrite rule that looked like
RewriteRule ^settings.php/(\w+)/(\w+)$ settings.php?level=$1&item=$2.
Very peculiar. So today I uploaded the new code, added the mod_rewrite module to the installed Apache engine and poked it. “Page not found.”
Poked around, and around, and around. First thing of note was that the deployed server didn’t need .php in the middle of the match string. I should point out here that the deployed server is Apache 1.3, so there’s probably some major differences between the development and deployment platforms 🙂 (Development platform being my personal laptop due to monetary issues when the company started.)
Second thing of note is that Apache’s mod_rewrite doesn’t use PCRE. I’ve checked the documentation, and unless I’m blind (which may be possible at a meta-physical level), the docs don’t state this . At all. A random page in a Google search revealed this to me. So, after going “Oh!”, I was able to rewrite my rules to something like
RewriteRule ^settings(.php)?/([a-z_\.-]+)/([a-z_\.-]+)$ settings.php?level=$2&item=$3,
and now have a rewrite ruleset that works on both servers with no changes.