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 if mod_status was configured correctly:
ExtendedStatus On
<Location /server-status>
SetHandler server-status
Order deny,allow
Deny from all
Allow from some_ips
</Location>
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
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# 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
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !=/server-status
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
>
Tags: htaccess, mod_rewrite, mod_status, WordPress

2nd March 2009, 10:34
I have multiple domains pointing to one wordpress 2.6.1(not updated in a while) installation and have customized .htaccess file to rewrite one of them to a subfolder which contains other html site.
A couple of days ago my custom rules vanished from .htaccess file. I administer server myself, so i’m pretty sure nobody else have done it.
.htaccess file was last modified at the same time i wrote a new post to wordpress and it was modifiable by apache user, so i think wordpress renewed it without letting me now.
That’s pretty strange, because the site was running for a couple of months and updated constantly, and it was the first time i encountered this problem.
Now i’ve written my custom rules before “#BEGIN wordpress” line, i hope it will not be removed again.
2nd March 2009, 10:40
@Andrius: that is strange… I would upgrade wp to the latest version 2.7.1; also I don’t think it is such a good idea to leave .htaccess writable by the web user. Myself I always make that read-only. hth.
2nd March 2009, 10:58
As i understand wordpress should only write to .htaccess when enabling pretty url feature:
http://codex.wordpress.org/Using_Permalinks#Using_.22Pretty.22_permalinks
In my case it was enabled from the start.
Wordpress creates permalink from the title of the post, and after publishing i found a typo in it, and renamed post _and_ url.
I think this was the reason to regenerate wordpress part of htaccess.
2nd March 2009, 11:00
yes, if you made a change in the permalink structure, that makes sense.
20th May 2009, 06:18
Super cool. Thank you very much and you managed to be #1 on Google for my search phrase. “wordpress 2.7.1 mod_rewrite rules” Nice job! I needed the rules for a WordPress installation on my very new blog, on a very new web hosting account. Hmmm .. After installing WP 2.7.1 over Fantastico, the .htaccess file was empty. Nothing there. Now that’s a problem when you try to install WP Super Cache. Anyway – Now all is good and works. Thanks again.
George
5th September 2009, 11:04
Thanks!
10th November 2009, 00:36
I still cant get /server-status working. It still shows me page not found.
31st January 2010, 04:15
i had similiar problem what sandeep has. Thanks anyway
31st January 2010, 04:37
I worked a lot of work thanks
30th March 2010, 15:53
[...] WordPress mod_rewrite rules taking over mod_status This is an interesting write-up of what happens if you've got a WordPress install at the same TLD where you keep your Apache server-status page. Basically, WordPress (quite correctly) ignores http requests for http://tld.com/server-status and dude shows you a sample apache rewrite for how to exempt requests for that specific URL from WP's automatic request redirection. Nice. [...]
5th July 2010, 05:04
[...] I’m posting here for my own notes. I give full credit to this site. [...]
12th August 2010, 20:20
[...] posting here for my own notes. I give full credit to this site. © 2010 Bash Bang Productions Inc. All Rights [...]
16th June 2011, 10:54
[...] After moving Rule of Tech to a new server and setting up monitoring I noticed that server-status and server-info Apache modules weren’t working as expected. As usual a little bit of Googling solved this problem. [...]
28th November 2011, 04:17
[...] Cercando un po’ ho trovato questa simpatica pagina quì. [...]