How To Create WordPress Redirects (301 Code)

Do you need to change your already shared and indexed page URL? Learn how to create WordPress redirects (301 code) without losing page rank

Updated on August 31, 2022
How To Create WordPress Redirects (301 Code)

Something happened, and you need to change your page URL. However, you already share this page URL, so see how to create WordPress redirects (301 code) without losing your page rank in this article.

You may want to redirect visitors to a different part of your website when they visit a particular page or post. Reasons for this can be that you renamed a post and its URL. A page was removed, or you want a different page to rank.

How To Create WordPress Redirects (301 Code)

Redirects in a nutshell

The name ‘redirect’ pretty much says it all: It sends visitors traveling from a specific page to an alternative one. But what does this 301 mean, and how does it differ from a 302 redirect? Both send your users to a different page. The only subtle (yet significant) difference is that a 301 will permanently send visitors and search engines to the new destination. 302 redirects indicate that you only temporarily want visitors to be sent to a different page.

Creating a 301 redirect on the server

One of the most basic methods of adding a 301 redirect is editing your .htaccess file on the server. This method is only available on Apache servers. Nginx has its way of defining redirects in the server configuration and requires extensive knowledge of system administration.

These configurations can get quite unmaintainable over time, especially if you’re an avid blogger. Or you’re trying to improve the SEO of your posts. On top of that, you would have to log in to your server over FTP. Edit the files and re-upload them every time you add a new redirect. That’s why, generally speaking, this method is not considered the way to go.

Creating a 301 redirect with PHP

Creating a 301 redirect with PHP
How To Create WordPress Redirects (301 Code)

As a WordPress developer, you have two options: Either you make a redirect by altering the headers of a file in the code. Or you make use of WordPress’ built-in
wp_redirect function.

An example of plain PHP could be as follows:

<?php
// MyExampleFile.php
header("HTTP/1.1 301 Moved Permanently"); 
header("Location: http://www.my-blog.com/a-new-destination"); 
?>

And this is how you’d do the same, but now by using WordPress’ built-in function:

wp_redirect( "http://www.my-blog.com/a-new-destination", 301 );

If you forget to add the 301both WordPress and PHP will assume that it’s a 302 redirect, which isn’t always the case.

This method is a bit easier than editing files on the server but can also become cumbersome once the amount of redirects increases.

Free method without coding to create WordPress 301 redirects 

In the video tutorial below, you’ll learn a more straightforward, effective, and free approach to creating your redirections without coding and paying for premium plugins.

Creating a 301 redirect with Yoast SEO

Creating a 301 redirect with Yoast SEO
How To Create WordPress Redirects (301 Code)

Our Yoast SEO Premium plugin offers you a helping hand when creating these redirects. Our built-in Redirect manager assists you whenever you change the URL of a post, page, or any taxonomies that may result in a possible 404 if you don’t correctly redirect visitors.

In addition, we also offer you an interface to edit or remove these redirects at a later point in time. The plugin also tells you when you’re about to create a redirect that will result in a redirect loop. This looping is something you want to avoid at all costs.

Server side solution

One of the most basic ways to create and add a 301 redirect is to edit the .htaccess file on your WordPress server. This method only works with Apache servers. Nginx has its own way of defining redirects in server configuration and requires extensive system administration knowledge.

These configurations can become very difficult to maintain over time, especially if you are an avid blogger or trying to improve the SEO of your posts. Also, every time you add a new redirect, you’ll need to log into the server via FTP, edit the files, and re-upload them. Therefore, using this method is generally not considered the correct method.

Last Words

If you’re doing a domain-to-domain redirect, make sure the new page is similar to the original. Content should reflect at least 70% of what was on the old site to minimize damage to your site’s SEO score.

Also, after completing the redirect, you should thoroughly check your site for broken links to make sure everything is working properly. You can find broken links in WordPress by following our guide.