How to create a 301 redirect in .htaccess for WordPress

If there’s one thing I always try to avoid with my WordPress sites it’s adding unnecessary plugins. Sure, there’s a plugin out there that will let you easily manage all of your redirects in WordPress called Redirection with over 1M downloads… but it adds weight to your database slowing your site down and cluttering your tables. Call me OCD but why slow your site down when you could just update your .htaccess file and create manual 301 redirects yourself?

Here’s why… it’s hard to figure out. It took me quite a few trial and errors and exploring the dozens of threads out there with lots of people trying to get this to work, unsuccessfully, but I finally figured it out and now you can use the solution too :)

  1. Use an FTP client to download your .htaccess file. I use dreamweaver but depending on your operating system and FTP tool this file may be tricky to download and disappear once you’ve got it because it begins with a period and operating systems identify those as system files and thus, keep them hidden so you don’t wreck your computer. One solution if you’re having this problem is to duplicate the file on your server then rename it to htaccess.html then download. Now you can edit it.
  2. Look for the section hear the bottom of the file that start out with # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On then go to the bottom of it just before </IfModule>
  3. You can paste your 301 redirect rules here, just above this closing </IfModule> tag and here’s an example
  4. Redirect 301 /folder/folder/ http://electricbikereview.com/newfolder/newfolder/
  5. You can also redirect files this way but always escape html redirects by using a forward slash like this Redirect 301 /folder/filename\.html http://electricbikereview.com/pedego/cruiser/
  6. Re-upload the .htaccess or htaccess.html file (and make sure you rename htaccess.html to .htaccess)
  7. Try to visit the page that you wanted to redirect and see if it works, you should just see a quick flash and  land on the correct page. Some hosts and systems cache these files so be a little patient. It usually works within 10 minutes for me

That’s it, now you can do all the redirects you want, just make sure you put them in the correct part of the .htaccess file because that opening tag and RewriteEngine On stuff needs to happen before your 301 can activate, this is a big part of why so many people fail at this, they put the redirect string in the wrong part of the file.

So that’s it, I know this doesn’t cover all use cases, feel free to chime in with the comments below or make any suggestions and additions you think will help people, I’ll update the article as they come in.