Recently while developing a site for a client, random WordPress pages were coming up as 404 Not Found, even though those pages definitely existed on the site. After digging through settings and code, I discovered that a plugin was continually adding repeating code to the site’s .htaccess file.

While a standard WordPress .htaccess might look something like this;

# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

The .htaccess on the development site was equal to these lines repeated over 1600 times!
This came to approximately 17,000 lines within the .htaccess and subsequently slowed the site down, and more and more pages were appearing as 404.
Further investigation of this file leads to finding several lines within the .htaccess that were corrupted (NUL).

The quickest fix is to backup your .htaccess, remove everything except those first 11 or so lines, from # BEGIN WordPress to # END WordPress.

However, this may not fix the actual cause of the problem. From extensive research, I still have yet to find a concrete solution/source to this problem, but it appears that any plugin that has to write to the .htaccess file is a suspect.
Furthermore, if you have caching and/or security plugins, or similar, the problem can be amplified and the .htaccess might be located in several locations on your server, in which case you should backup the site, and search for any *.htaccess files, and make sure they don’t contain repeating code.

Report This Post