aaltonen.us

A comprehensive archive of historical posts.
« Back to blog
Mar 2
Views

Does Not Play Well With Others

There's an issue with WordPress 2.0+ and its rather aggressive generation of URL rewrite rules. It was never an issue previously, as WordPress would generate mod_rewrite rules to either automatically or manually be updated in the root .htaccess file. As expected, the extra step of chmod-ing the .htaccess file or manually editing the rules was a minor pain -- one for which the WP developers discovered a "solution." The new generation of rewrites are handled internally by the WordPress engine. This approach causes a problem: at any one time a web developer doesn't know the current state of mod_rewrite rules being used. Also, the rewrites can cause problems with non-WP-related subdirectories or subdomains that use their own .htaccess files. For example, I was unable to password-protect a subdirectory under the root WP install, regardless of any updates I made to the rewrite rules I saw in .htaccess. The instant I placed the .htaccess file in the subdirectory, WordPress went nuts and didn't allow me in the directory at all, instead placing me straight back at the WP index page. I tried a number of fixes suggested on the WordPress forum and other sites, but nothing was successful in telling WordPress to exclude my subdirectory. The suggested solutions are hacks at best, regardless, because it requires one to explicitly exclude, instead of the better practice of implicit inclusion for WordPress's pages and permalinks. This is a widespread problem that the WP developers should rethink going forward. Fortunately, I discovered a simple fix while digging through the PHP code in an attempt to see how the rules were being dynamically generated. Change $use_verbose_rules to true in WP-includes/classes.php. This will cause WP write the rules it needs dynamically into the root .htaccess file, instead of its default internal handling. This will makes the WP-generated .htaccess file a bit bigger and complex, but since it only writes the rules it needs, it leaves the rest of the site unharmed. Good enough for now. Bad WordPress, but I still forgive you.

Leave a comment...