I'm not exactly sure why, but when my hosting provider upgraded to Apache 2.2 and PHP 5, my RewriteRules for Wordpress stopped working properly. You may have noticed this in that when you clicked to make a comment it would send you back to the front page.

This probably has something to do with the way Apache handles rewrites internally, and I suspect that it's happening to a lot of people. Maybe it's just a symptom of how my webhost is configured, but maybe it's Apache's fault.

Up until a couple of weeks ago I had these lines:

<ifmodule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . https://digitalelf.net/index.php [L]
</ifmodule>

This is pretty standard, and it's what WordPress tells you to do. Unfortunately it doesn't work for me anymore. For anybody who understands what this means, Apache was acting if my rewrite rule had [R] at the end of it. Since the redirect is not there, but Apache was redirecting anyway I think this is an Apache bug. Some have claimed that it's due to the way Apache 2.2 and PHP5 are interacting with each other. I don't know.

How to fix this? Well, since all WordPress really needs is to have the request URL passed directly into index.php unchanged I decided to use ErrorDocument, because it seems to use the same behavior that I previously relied on mod_rewrite to do.

My newly adjusted .htaccess file (in its entirety) looks like this:

ErrorDocument 404 /index.php

I know this is wrong, but it's better than nothing. Apache is still serving up pages as they should be if mod_rewrite were working properly, and all the requests still have their proper return codes. However, my actual 404's end up displaying as my front page, instead of letting you know the page doesn't exist.

UPDATE: I figured it out. It's because I had the domain in my RewriteRule. Here is the final (and finally corrected).

<ifmodule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
</ifmodule>