Why Your .htaccess Redirects Never Work in WordPress

For years, I kept making simple .htaccess 301 redirects for old pages on my WordPress sites, and they never seemed to work! It was incredibly frustrating, especially since I would always test out my redirects with an .htaccess checker, and they would always pass. I kept thinking maybe I just didn’t have the required mastery of regular expressions, or possibly I was just stupid.

Note that if you’re having issues with your .htaccess file on Godaddy hosting or another shared hosting provider, you may just have a different issue.

Turns out it’s neither! Well, okay, maybe both are still true. But in this case that wasn’t why my .htaccess file wasn’t working. I could go on and build this up, but there’s really only one thing, and here it is:

Q: Why isn’t your .htaccess redirect working?

A: Because your redirect needs to go before the WordPress section of the file!

Yes, it really is that simple. Your redirects are probably formatted just fine, you just need to place the code for the redirect before the WordPress section. You still might need to include RewriteEngine On at the beginning of your file, though I usually don’t. But that’s it!

Why does this work? You see, WordPress is always trying to rewrite the URLs of pages so they look nice and pretty. If it does it to a page you wish to redirect, and it does it before your code runs, the URL will be different and of course the conditions will not match your redirect rule.

Let me show you!



You see, it’s really quite easy! Somehow, nobody seems to ever mention it, and I thought I would. Let me know in the comments if this was your problem, or if you have something else going on!

About Brian Johnson

Brian Johnson is a website developer and designer living in Minneapolis, Minnesota with a passion for code and WordPress. He spends his days building WordPress websites for small businesses, developing new code with the online community, and living life.