Find out how to create a 301 redirect in WordPress • Yoast


Do you need to create a 301 redirect in your WordPress site? You are in the right place! We are going to show you how to set up 301 redirects using 4 different methods. Not sure if you need to use a redirect or if a 301 redirect is the right choice? Don’t worry, we’ll explain that to you too.

Redirects in a nutshell

The name ‘redirect’ says it all: it directs visitors who travel to a specific page to an alternative one instead. Or, if there is no alternative, an HTTP header (these are similar to redirects) can make this clear to users and search engines. It’s a bit like registering a change of address when you move. What if an old friend comes to your house to visit you? A forwarding is like a note on the front door telling your visitors where you are currently living. Every time you change a URL or delete a page, think about redirects.

There are different redirects for different purposes. Since this post is all about 301 redirects, let’s look at a few situations where you may need to use a 301 redirect.

When should you use a 301 redirect?

A 301 redirect should be used when:

  • You have permanently deleted a page on your site, but you want to direct users to another, similar page instead
  • You have changed the URL of a page that has already been published
  • You’re moving your website to a new domain
  • You change your URL structure, e.g. B. from HTTP to HTTPS or remove “www” at the beginning of your URL

These are some of the most common reasons for using a 301 redirect, but there are other situations that require the use of redirects as well. In addition, there are other redirects and HTTP headers that you can use in other situations. For example, if you permanently delete a page and there is no suitable replacement or replacement to send users to, you will need to use a 410 redirect. We have a completely different post where you can learn more about which redirects to use in which situations.

Option 1: Create a 301 redirect on the server

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

These configurations can get pretty unsustainable over time, especially if you’re an avid blogger or trying to improve the SEO of your posts. In addition, you’d have to log into your server via FTP, edit the files, and re-upload them every time you add a new redirect. Because of this, using this method is generally not considered the right way to go.

Option 2: create a 301 redirect using PHP

As a WordPress developer, you have two options: Either you perform a redirect by changing the headers of a file in the code – or – you use the built-in functions of WordPress
wp_redirect function.

An example of simple PHP could look like this:

Option 3: Create a 301 redirect using the built-in WordPress feature

Here’s how you’d do the same thing, but now with WordPress’ built-in functionality:

wp_redirect (“”, 301);

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

This method is a little easier than editing files on the server, but it can also become cumbersome as the number of redirects increases.

Option 4: Easily create a 301 redirect with Yoast SEO

Our Yoast SEO Premium Plugin offers you a helping hand when it comes to creating these redirects. Our integrated redirect manager supports you whenever you change the URL of a post, a page or one of the taxonomies that can lead to a possible 404 if you do not redirect visitors correctly.

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

Read more: How to properly delete pages from your website »

Edwin Toonen

Edwin is a specialist in strategic content. Before joining Yoast, he spent years honing his skills at the leading web design magazine in the Netherlands.


Don’t miss these tips!

We don’t spam! Read our privacy policy for more info.

Leave A Reply

Your email address will not be published.