MurkyGoth's Mutterings

Well, that was harder than I expected…

August 29th, 2008 by murkygoth

Just getting this WordPress blog to behave – mod_rewrite was doing unexpected things, which sucks.

The normal rewrite rules that you put in for the date/slug URLs didn’t work:


RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

This didn’t seem to make any of the checks, just rewriting everything to ‘index.php’. Needless to say, this kinda screwed up the CSS 🙁

Turning on logging for mod_rewrite showed that for some reason it was only using the URI part (e.g. ‘/2008/08/08/vista-the-devourer-of-disk-space/’) without the document root prepended, so of course the conditions failed and the address was rewritten. During the rewrite, however, the document was prepended, so the ‘index.php’ worked fine!

My horrible hack to get it working?


RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Yep, explicitly add the document root to the URLs before checking. It does introduce a double slash (%{REQUEST_FILENAME} has one) but that doesn’t seem to affect it much.

Still, all looks good now. 🙂

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.