Add 301 redirects using .htaccess

Over the course of time a WordPress blog or site author is bound to change the content of their site and eventually move or even delete and rewrite content. This can cause problems with search bots that have previously crawled and indexed your links. If the moved or deleted links can't be found, resulting in a 404 Page, over time, you might even lose page ranking.

To remedy this we can utilize the 301 redirect rule to point the old path to the new location. The easiest way to do this is via the .htaccess file. Here's How;

How to Add 301 Redirects to htaccess (WordPress)

  1. Access your blog directory via FTP
  2. Locate and copy the .htaccess file to your computer
  3. Open the .htaccess file using a text editor (I recommend using the 7-zip text & code editor - it's free).
  4. Under the line # END WordPress add the following code (changing the paths as necessary):
    redirect 301 /oldpath https://www.yoursite.com/newpath/

Note that if you want to 301 redirect more than one page, you can add multiple copies of this line - one for each additional path you redirect.

How 301 Redirects work

301 signifies a permanent redirect. Meaning that the old path has permanently moved. There are other redirects such as 302 that produce a temporary redirect. Those are useful for situations when you don't know exactly what you want to do with the old path yet, and want to simply redirect to somewhere temporarily, before making a permanent decision. You can replace redirect 301 with redirect 302 in the code above, if you'd like.

The first section of the code redirect 301 /oldpath signifies the path that no longer exists. In this example the path that no longer exists is /oldpath. Note that your server treats this path "relative to root" as https://www.yoursite.com/oldpath
You can also redirect an old .html or .php file by adding the extension. For example: /oldpath.html

The second section of the code http://www.yoursite.com/newpath/ tells the server where to route the old path. This new path must be a full URL to the new location... but note that it can link to any website. So yes, you could even add 301 redirect and point the old path to a completely different site.