Need to create a 301 redirect in your WordPress site? You’ve come to the right place! We’ll show you how to set up 301 redirects using 4 different methods. Not sure if you need to use a redirect, or whether a 301 redirect is the right one to choose? No worries, we’ll explain that too.
Redirects in a nutshell
The name ‘redirect’ pretty much says it all: It sends visitors traveling to a specific page to an alternative one instead. Or, if there’s no alternative, an HTTP header (these are similar to redirects) can make that clear to users and search engines. It’s a bit like registering a change of address when you move house. What if an old friend goes to your old home to pay you a visit? A redirect is like a note on the front door, telling your visitors where you’re living at now. Any time that you change a URL or delete a page, you should be thinking about redirects.
There are different redirects for different purposes. As this post is all about 301 redirects, let’s look at some situations where you might need to use a 301 redirect.
When should you use a 301 redirect?
A 301 redirect should be used when:
- You’ve permanently deleted a page on your site, but you have another similar page you want to send users to instead
- You’ve changed the URL of a page that was already published
- You’re moving your site to a new domain
- You’re changing your URL structure, e.g. changing from HTTP to HTTPS, or removing ‘www’ from the start of your URL
These are some of the more common reasons for using a 301 redirect, but there are other situations that require using redirects, too. And besides that, there are other redirects and HTTP headers you can use in other situations. For instance, if you permanently delete a page and there is no suitable replacement or substitute you can send users to, then a 410 redirect is what you need to use. We’ve got a whole other post where you can read 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 by editing 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 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 on your server over FTP, edit the files and re-upload them every time you add a new redirect. That’s why, generally speaking, using this method is not considered the way to go.
Option 2: Create a 301 redirect with PHP
As a WordPress developer, you have two options: Either you make a redirect by altering the
This article was written by Edwin Toonen and originally published on SEO blog • Yoast.