Thursday 26 June 2014

Wordpress mod_rewrite rules taking over mod_status

While working on setting up a monitoring solution for a big wordpress installation, I realized that the server-status url was not working as expected even ifmod_status was configured correctly:


ExtendedStatus On


SetHandler server-status
Order deny,allow
Deny from all
Allow from some_ips


The .htaccess wordpress rules were taking over this and the server-status url was returning a page not found error from within wordpress. This was happening because of the way how the rewrite rules are setup to handle all the permalinks on the site, and for any non-existing file send it to index.php:
# BEGIN WordPress


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


# END WordPress

This works fine with any aliases defined in apache, but the mod_status handler was going to the rewrite rules first, hence the problem. This is not a wordpress problem, and should happen with any other application (like zend framework is one other example that comes to my mind right now) that uses the same type of catch-all rewrite rules to handle all the urls inside the application. The solution in this case is to specifically add a rewrite rule to not have the server-status url processed and sent to the default rule:
RewriteCond %REQUEST_URI !=/server-status
and the wordpress rewrite rules should look like this:
# BEGIN WordPress


RewriteEngine On
RewriteBase /
RewriteCond %REQUEST_URI !=/server-status
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule . /index.php [L]


# END WordPress



Wordpress mod_rewrite rules taking over mod_status

No comments:

Post a Comment