More htaccess fun

More trouble from the Observer hosting change. The wordpress blog gave me the same “No Input File Specified” error and this time adding the ‘?’ and forcing the queries didn’t work. There wasn’t too much about it either on the searches.

Our Wordpress installation formatted URLs like this:

http://www.texasobserver.org/blog/index.php/2009/04/09/post-title/

causing the error so I reformatted them to just use the post id:

http://www.texasobserver.org/blog/?p=1317

This is all fine but now I have to worry about when other sites use our posts as referrals because those old urls give the damn error. All I really need to do is reroute the old urls to the new ones in the htaccess file but how do you go from title to post id?

I was able to figure out that each url segment represented a GET variable that the controller was using to pull the correct post to the top and that the last segment was used by the convienently named GET variable ‘name’. So all I need to do is change the original URL to

http://www.texasobserver.org/blog/index.php?name=post-title

This was easily accomplished with a simple rewrite rule in my htaccess file:

RewriteRule ^blog\/index\.php\/([0-9]+)\/([0-9]+)\/([0-9]+)\/(.*)$ /blog/index.php?name=$4

Pretty crazy, huh? The old URLs were formatted with index.php/year/month/day/name so we have 4 regular expressions separated by forward slashes. Year, month and day are easily found with <[0-9]+>, which finds strings that have only digits in the range of 0-9 and a length of at least 1, and we keep the entire URL name with <.*>, which finds strings of any length with any character. We only use this last part in the reroute so we can set aside $1 (year), $2 (month), and $3 (day). All we need is $4 (name). If you don’t know what I’m talking about you should read up on how htaccess files work.

The good news is I got it to work. It just sucks it didn’t work right away. From what I’ve been reading it’s a php/apache install setting but I dunno. I don’t really feel like spending the time on the phone with tech support trying to figure it out.

Now I can move on to bigger things. Like migrating the blog into Expression Engine. That’s gonna be fun. I assume I will be writing some pretty crazy SQL scripts this summer.