Are you trying to create a 301 redirect WordPress?
Don’t know what the redirect is and why it’s important?
Don’t worry, in this article, we will introduce what it’s like to 301 redirect in WordPress, how to do it, why you need it, and when you should use redirection.
Are you ready? Let’s get started.
What is the redirection in WordPress?
Redirect is your site by sending a quick message to a reader’s browser and telling him that the page you want to visit has been moved, so your browser can automatically direct them to a new page of your choice.
There are several different types of redirection, such as 301 redirections, 302 redirections, 307 redirections, etc. But to make the article simple and useful, we will only introduce 301 redirects because that’s what matters most.
Let’s see why it matters in understanding the use case.
When do you need 301 redirect WordPress?
The main reason for using 301 redirects is that you want to point users to a new page when the site or site page is moved.
The idea of this post came to us when one of our readers asked us to redirect users from old posts to new ones.
- When you plan to delete a post or page to support new content, you must create a redirect.
- When you plan to change a permanent link to a post or page, you need to create a redirect.
Why?
Because you do not create a redirect, users will see a 404 errors not found. This is not only bad for users but can also affect the ranking of your site’s search engines and compromise your search engine ranking.
This is when the 301 redirect becomes very important. It allows you to tell search engines and browser users that the page they are trying to access has been permanently moved to a new location.
This allows the traffic advantage and backlink (SEO) of all your old pages to switch to the new page.
Now that we’ve covered the reasons and redirection times, let’s see how to create 301 redirects in WordPress using different methods.
How to create a 301 redirect WordPress (using plugins)?
An easier way to create and manage a 301 redirect is to use one of the many WordPress redirection plugins.
This allows you to set redirects without writing a single line of code.
#1 Redirection
The easiest way to add and manage 301 redirect WordPress is to use the redirect plug-in. Install and activate the add-in. Once enabled, access the “tool redirection” to configure your redirection.
The redirection plugin not only allows you to set redirection but can also help you figure out 404 errors on your WordPress website. You can then redirect those URLs to a suitable destination.
#2 Page Links to
Page Links to plugin adds a meta-box to the post editing screen where you can enter the address of the new location you want to send to the user.
#3 Simple 301 Redirects
As the name suggests, it makes 301 redirect simple. Just install and activate the plugin and then visit Settings” 301 redirects to add your URL.
Now, while setting 301 redirects with the Simple 301 Redirects plugin is easy, it has some minor performance setbacks.
Depending on your WordPress hosting provider, your WordPress redirection may be a few microseconds slower.
If you want your redirection to be faster, you can do this by using code methods and .htaccess files.
Set 301 Redirect WordPress using .htaccess
With .htaccess web server configuration file, WordPress users can configure 301 redirections quickly.
Note that a small error in the .htaccess code may make your WordPress website inaccessible and may start showing internal server errors.
That’s why it’s important to back up the .htaccess files before making any changes. Edit your .htaccess file, you need to connect to your website using FTP client. The htaccess file resides in the root directory of your WordPress website.
If you can’t see your .htacces file there, then you need to force your FTP client to show hidden files. (See why you can’t find the. htaccess file on your WordPress site.)
You can edit the .htaccess files in any plain text editor, such as Notepad. Here is a simple redirect where we try to send users accessing old posts to new ones.
RewriteEngine On Redirect 301 /a-very-old-post/ http://yoursite.com/a-very-new-post/
You have to add the above code to the end of the .htaccess file.
Create 301 redirect WordPress with PHP
As a WordPress developer, you have two options: either redirect by changing the header of the file in the code – or – use the wp_redirect function.
An example of a normal PHP may look like this:
<?php // MyExampleFile.php header("HTTP/1.1 301 Moved Permanently"); header("Location: http://www.my-blog.com/a-new-destination"); ?>
Here’s how you do the same, but now using the built-in WordPress function:
wp_redirect( "http://www.my-blog.com/a-new-destination", 301 );
If you forget to add 301, both WordPress and PHP will assume that it is a 302 redirect, which is not always the case.
This method is a little easier than editing a file on a server, but once the redirect vector increases, it can also become cumbersome.
We hope this beginner’s guide to creating 301 redirect WordPress will help you set redirects on your website.
In case of any further problems, you can contact us via mail, chat, or call. You can just drop in a comment below, we will contact you asap.