2009/08/10
Do Not Rewrite HTAccess
I wrote my first WordPress plugin today: Do Not Rewrite HTAccess. I have been working to implement the same kind of rewrite scheme for my WordPress blog as Chemo’s Ultimate SEO URLs addon does for osCommerce. I have static mod_rewrite rules saved in my .htaccess file that handle both a root level osCommerce shop and a WordPress blog. These rules are more limited and focused than the standard WordPress rewrite rules. As such, I don’t want to add the standard WordPress rules to my .htaccess file.
Since WordPress is not set up to both generate pretty URLs and not rewrite the .htaccess file, I’ve had to take steps. My first stab at this was to simply make the .htaccess file non-writeable. Doing this worked, but meant that I couldn’t easily edit the .htaccess file. Worse, if I did anything in my host’s cPanel that would modify the .htaccess file, the host would automatically make it writable and WordPress would hop in and make changes.
This plugin overrides got_mod_rewrite to return false when called by save_mod_rewrite_rules. Since save_mod_rewrite_rules uses got_mod_rewrite to determine if it should generate and save the rewrite rules in .htaccess, this had the effect of disabling save_mod_rewrite_rules. The only hard part about this was making sure that got_mod_rewrite continued to return true when called to determine if pretty permalinks are to be generated. If I had just turned it off entirely, I would been stuck with index.php in my URL.
You can get the plugin here: Do Not Rewrite HTAccess
Update: I originally wrote this in July. However, my url rewriting was not working with attachments in the way that I wanted, so I wrote my second WordPress plugin before posting this. However, that’s a story for another day (and another post).