We recently moved a site that based on Joomla to WordPress. However, we needed to add a few new rules to our .htaccess in order to match some of the old URLs up to the new ones. So we went ahead and added the rules.

After a few days we check our Google WebMaster tools and guess what?!? We had an abnormally large amount of 404 pages. We began to go through and look at them, and realized that Google was still getting 404 errors on the pages we had already redirected. Very odd.

So of course we pop open our .htaccess page and all of our changes are GONE!

As it turns out, WordPress rewrites the .htacess file to include the rules that it needs to run. Anything in the “wordpress block” gets erased. That is, anything you put in this block will be erased:

# 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

I thought it made sense to just add my rules after the RewriteEngine was On and the RewriteBase was set, so I had put my rules on line 5 of this code snippet. So what we did instead was place our rules outside of this WordPress block so it looks more like this:

# 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

# BEGIN 301 Redirects Joomla to WordPress
<IfModule mod_rewrite.c>
RewriteEngine On

RewriteBase /
RewriteRule (match1here|match2here|match3here)/\d{1,3}-([\w-]*)/\d{1,3}-(.*) $1/$2/$3 [R=301,L]
RewriteRule component 404.php [R=301,L]
# End 301 Redirects Joomla to WordPress

So if your htaccess file is being rewritten in WordPress, make sure your rules are outside of the WordPress block, and you should be just fine!

(We got the fix from this article, so check it out if you want more info:Keep WordPress from Overriding Custom Htaccess Rules