Mad code rewrite
 
Photo by zhartley

Scrawlers, an online writing workshop I helped build, includes a blog. Rather than build the blog from scratch, or even use a Rails solution, I chose to stick with the familiarity of WordPress. I’d read enough about Rails-lovers switching to a Rails-based engine and back to WordPress that I wasn’t even going to bother leaving The WP.

Scrawlers sits on an Ubuntu server with Apache and Mongrel running. Unfortunately I have little to no server admin skill, and that includes Apache mod_rewrite. Ilya Grigorik posted an excellent HOWTO on integrating WordPress and Rails. Unfortunately it didn’t quite work for Scrawlers, and I put off figuring out my special mod_rewrite secret sauce for quite a while.

Eventually I figured out what I needed beyond Ilya’s original technique and posted it in the comments section of his blog. The completist in me needs to post the solution on my blog as well. What follows is pretty much word-for-word from Ilya’s comment section. Be sure to read his post. It’s an easier solution, if it works for you, and it provides background information for what follows.

I’m dealing with Apache configuration that I do not understand. So it turns out I have AllowOverride disabled on my server, even explicitly in my app-specific Apache configuration for the public directory. This is why .htaccess wasn’t working for me.

After reading up a bit on .htaccess/AllowOverride, I decided there was really no reason to turn it on and eat the overhead involved. Instead I made a Directory directive in my app-specific config file and placed it before my initial WordPress redirects.

Once these things were in place, the one-line RewriteRule worked in every instance except one. The URL http://www.scrawlers.com/blog (or /blog/) failed with an access denied error. Looking at the rules it sure appeared like it should work. In the end I needed to include a couple rules specific to these situations. Here is, essentially, the bit of configuration code I needed to make my blog start working naturally: