.htaccess, WordPress and CustomError Pages Oh My!

This site runs WordPress, I also run WordPress on most of my money making niche VRE sites. WordPress does a great job and with plugins like wp-cache and All in One SEO Pack it makes getting a site up with search engine friendly URLS and meta content. It also makes it very easy to add content to your site so you stay indexed and relevant.

One of the big problems I was having recently was WordPress Permalinks we’re causing my awstats to not show up. It looked like mod_rewrite was doing something to the urls and they were being lost.

This didn’t really bother me much because I didn’t look at my stats all that often and when I wanted to take a peak I would disable the .htaccess, take a look then re-enable it.

Tonight this was starting to bother me because it becomes time consuming when you want to look at statistics for 12 sites. I decided to try and see if I could work out the root cause and fix it.

After about 30 minutes of reading and testing various settings I was confused so I decided
to enable mod_rewrite’s rewrite_log option with the RewriteLogLevel set to 9.

Looking at snip from the rewrite_log: – – [30/Oct/2007:21:21:24 -0400] [www.stupidfoot.com/sid#87f0494][rid#87ff3c4/initial] (2) init rewrite engine with requested uri /awstats/ – – [30/Oct/2007:21:21:24 -0400] [www.stupidfoot.com/sid#87f0494][rid#87ff3c4/initial] (1) pass through /awstats/ – – [30/Oct/2007:21:21:24 -0400] [www.stupidfoot.com/sid#87f0494][rid#8956514/initial/redir#1] (2) init rewrite engine with requested uri /401.shtml – – [30/Oct/2007:21:21:24 -0400] [www.stupidfoot.com/sid#87f0494][rid#8956514/initial/redir#1] (1) pass through /401.shtml – – [30/Oct/2007:21:21:24 -0400] [www.stupidfoot.com/sid#87f0494][rid#8956514/initial/redir#1] (3) [per-dir /home/myhostinguser/domains/stupidfoot.com/public_html/] strip per-d
ir prefix: /home/myhostinguser/domains/stupidfoot.com/public_html/401.shtml -> 401.shtml – – [30/Oct/2007:21:21:24 -0400] [www.stupidfoot.com/sid#87f0494][rid#8956514/initial/redir#1] (3) [per-dir /home/myhostinguser/domains/stupidfoot.com/public_html/] applying pattern ‘.’ to uri ‘401.shtml’ – – [30/Oct/2007:21:21:24 -0400] [www.stupidfoot.com/sid#87f0494][rid#8956514/initial/redir#1] (4) RewriteCond: input=’/home/myhostinguser/domains/stupidfoot.com/public_html/401.shtml’ pattern=’!-f’ => matched – – [30/Oct/2007:21:21:24 -0400] [www.stupidfoot.com/sid#87f0494][rid#8956514/initial/redir#1] (4) RewriteCond: input=’/home/myhostinguser/domains/stupidfoot.com/public_html/401.shtml’ pattern=’!-d’ => matched – – [30/Oct/2007:21:21:24 -0400] [www.stupidfoot.com/sid#87f0494][rid#8956514/initial/redir#1] (2) [per-dir /home/myhostinguser/domains/stupidfoot.com/public_html/] rewrite 401.shtml -> /index.php

From that we learn that I have ErrorDocument 401 /401.shtml which means all requests for authenticaton are being sent to /401.shtml and because I don’t have a 401.html we get redirected back to /index.php and index.php thinks we have a story called awstats which we don’t.

There are a few ways you can solve this.

  1. Disable the ErrorDocument by adding ‘ErrorDocument 404 default’ to your .htaccess file
  2. Remove or set ‘ErrorDocument 404 default’ in httpd.conf or your vhost.

I chose method 2 because it was less work for the 12 sites I have running. This setup of custom ErrorDocument(s) is done by some hosting packages, Cpanel and DirectAdmin just to name two.

This should help all of the people who have been having similiar problems who I’ve seen posting on the WordPress forums.

Be Sociable, Share!