People create redirects for several reasons. In fact, 99% of redirects are created when the website owners change their URL structures or when they have altered the post slug of a page. Whenever the reason is, redirects are very important as they retain your visitors by leading them from your deleted page to your newly updated page. The 301 redirect comes into play. In the following, we have listed some simple ways on how to create a 301 redirect in WordPress by the use of .htaccess, PHP and a redirection plugin.
What is 301 Redirect?
Actually, the redirect practice is an effective way to send the messages to both your readers and the search engines about the fact that the page they are looking to visit or index has already been removed. In this case, they can be pointed to the new page automatically without the possibility to meet the 404 error.
In fact, the 301 redirect is the most commonly used redirect used by the majority of webmasters. It informs search engines and online visitors when a page has been permanently moved to a new location. It is for this reason that we highly recommend you use this redirect whenever you move your webpages. After all, with a 301 redirect, the rank of your deleted page and any other juice from a search engine are retained.
In addition to the 301 redirect, there is also a 302 redirect available, performing the same functions as that of the 301 choice. However, the difference is that while 301 redirect indicates the permanent moving, the 302 redirect means the temporary moving.
Now, the question is when you’d better add the 301 redirect? Here, we have listed some situations.
- You have changed the directory of the whole WordPress installation.
- You have transferred your site to a new domain name and worry about the drop of the online ranking.
- You have changed the permalink settings of your website.
- You want to consolidate various blog posts into one.
Frankly speaking, by doing so, you can get the following two main benefits.
- Great user experience – You must want your readers to land on the right pages when they click your website links. In this case, the 301 redirect can guarantee that even if you have changed the URL or have moved the content, everyone can check the content you want them to see. The 404 error that may disappoint people will not happen.
- SEO reasons – Actually, the old links already get the link juice after being indexed by a lot of search engines. By adding the 301 redirect, you can retain the link juice so as to keep your online ranking.
Redirect a Page Using 301 Redirect
.htaccess is a file used by Apache web server to control the website URL rewrite. You can read this page to learn the syntax of .htaccess in the detail.
Here, you should make sure that you bear the enough knowledge to edit your .htaccess file. After all, a minor mistake may crash your whole WordPress site. Here, we highly recommend you to make a backup for your .htaccess file before you make any change on it.
To connect this file, you can use the FTP client. Note that the file is located at the root directory of your site. Or, if you use the Yoast SEO plugin on your site, you can leverage its File Editor tool. Here, you simply need to click the SEO > Tools button of your admin. Among the listed tools, you should click the File Editor button. Here, you can find two boxes. One is for robots.txt file and another is for .htaccess file. Here, you should edit the latter one with the simple redirect code highlighted in the following.
After save the .htaccess file, the redirection takes into effect immediately.
Also, you can write 2 simple lines of PHP scripts for the redirect as below,
header("HTTP/1.1 301 Moved Permanently"); header("Location /newpage.html");
Ensure that the code is placed at the top for it to work correctly. The line that informs “301 permanently moved” is important to advice search engines that the page has been moved.
Using a Redirection Plugin
A WordPress redirection plugin is an easy alternative to PHP script or .htaccess. It comes handy for those who are not well versed with the technical world. One great plugin is the Redirection Plugin. The plugin, besides allowing you to perform a 301 redirect, it also allows you to perform a 307 and 302 redirect. Once the plugin is installed in your site, it will automatically add redirect when you change the URL slug of a post.
Get the plugin from WordPress.org and install it from your WordPress dashboard. After you have installed the plugin, go to Tools >> Redirection.
Input the old URL and the new URL. After that, click “Add Redirection” and the redirection is ready.
Also, you can read into this list of our reviewed WordPress redirection plugins.