How to add the redirect code to your WordPress pages

If you ever change the url of a page or a post and a visitor then visits the old url they will receive an error message saying the page they were looking for couldn’t be found. This isn’t because it doesn’t exist; it’s just because it’s been moved.


In this article we will look at how to alert a user’s browser that the location has changed and where the new one is. This is called a 301 redirect. You’ll need to create a redirect if:

  1. You are planning on deleting a post or page in favour of new content
  2. You are planning on changing the permalinks of your post or page

Using plugins

The easiest way to add redirects to your site is by using a plugin such as Simple 301 Redirects or Redirection. While using a plugin for redirects is easy, it has some minor performance setbacks. Depending on your WordPress hosting provider, your WordPress redirects may be a bit slower by some microseconds.


Install and activate the plugin. Once activated, visit Tools » Redirection to setup your redirects.


The redirection plugin not only allows you to set-up redirects, it also helps you find out 404 errors on your WordPress site. You can then redirect those URLs to an appropriate destination.

Simple 301 redirects

Another easy-to-use plugin is Simple 301 redirects. As the name suggests, it makes 301 redirects simple. Simply install and activate the plugin and then visit Settings » 301 Redirects to add your URLs.


Setting up 301 redirects in WordPress using .htaccess

Using the web server configuration file .htaccess, WordPress users can set up 301 redirects that are fast.

Please keep in mind that a small mistake in your .htaccess code can make your WordPress site inaccessible, and it may start showing Internal Server Error.

That’s why it is important that you backup your .htaccess file before making any changes.

To edit your .htaccess file, you will need to connect to your website using an FTP client. The .htaccess file resides in your WordPress site’s root directory.

If you can’t see your .htaccess file there, then you need to force your FTP client to show hidden files.  

You can edit your .htaccess file in any plain text editor like Notepad.

Here is a simple redirect, where we are trying to send a user visiting an old post to a new post.

RewriteEngine On
Redirect 301 /an-old-post/

You can add the code above preferably at the end of your .htaccess file.

Related Articles

Get online with our affordable web hosting

Get online with our affordable web hosting

Learn more now
HostPapa Mustache