‘404 – Page Not Found’ Error When Commenting on a WordPress Site

The comment function broke on one of the WordPress sites I manage. When submitting a new comment, users would receive a “404 Page not found” error. My first thought was that a theme or security plugin update was the cause, so I switched to the basic 2015 theme and reviewed all of the site security settings. My second thought was that something happened to either the wp-comments-post.php or .htaccess files. The wp-comments-post.php file had the correct permissions and the byte count/date modified were good. The WordPress section of the .htaccess file had the default contents. I wasn’t sure about some of the other lines, but assumed they were probably put there by the security software. I read through about 2 dozen different forums and articles on this topic before I found a solution that worked. Here’s a brief recap of the various solutions that worked for one or another site owner:

Try these steps to fix a 404 Page Not Found error when submitting comments on your WordPress blog.1. Change permalinks to Plain. (This gave me a blank page instead of a 404. This should have been a dead giveaway. Ignorance is my only excuse, and it’s not much of one.)
2. Change permalinks to some other format. (I changed it to “day and name”, and the 404 errors came back.)
3. Fix malformed custom permalink string. (I wasn’t using a custom permalink string, and either of the above two should have fixed it if I were.)
4. Disable the “Break comments into pages” feature. (No change.)
5. Does the wp-comments-post.php file exist and is it accessible to site visitors? (Yes and yes.)
6. Make sure WordPress section of .htaccess file contains only the default settings. (No change.)
7. Rename .htaccess file in case something in it is causing a problem. (No change. Renamed it back.)
8. Switch to one of the basic WordPress themes. (I tried two of them. No change.)
9. Manually restore all of the original WordPress files. (No change.)
10. Deactivate all plugins. (No change.)
11. Reset all security plugin values to default. (No change.)
12. Remove all security features. (No change.)
13. Double-check .htaccess file contents. (Bingo!!!)

Once all of the security modifications had been removed, the .htaccess file should have contained nothing but the basic WordPress settings. Mine didn’t. It had four extra lines:

RewriteOptions inherit

RewriteEngine on

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress
RewriteCond %{HTTP_HOST} ^domain.com$
RewriteRule ^/?$ “http\:\/\/www\.domain\.com\/” [R=301,L]

I know what the two Rewrite lines at the end are for. They make sure that anyone who browses to http://domain.com is redirected to http://www.domain.com. This is for SEO purposes more than anything else.

But why was there a second “RewriteEngine on” line before the WordPress section? And where did the “RewriteOptions inherit” line come from?” I have no idea, but as soon as I saw that, I knew exactly what the problem was. There was another .htaccess file one directory higher up the tree, and this line was carrying all of that file’s settings over into this one. I don’t know exactly which line in the parent’s .htaccess file was hijacking the comments function, but that had to be it.

Commenting started working again after I #ed out those two lines.

Leave a Reply

Your email address will not be published. Required fields are marked *