If you’ve ever modified a URL or permalink structure on your website without adding a redirect, you’re in for a world of trouble.
Why is that?
Simply put, changing URLs without adding a redirect can cause issues for search engines such as Google, which may not index your content properly and can negatively affect your ranking.
On top of that, redirects can also be a huge pain for users.
If a broken link is found on your site, users will have missed out on a great opportunity and will likely never return to your site.
How do you add a redirect to your site?
You can either manually add a redirect or use a plugin to add a redirect.
Let’s take a look at both ways to add a redirect in WordPress in this post.
What are Permanent Redirects?
Adding redirects in WordPress manually
In order to manually edit redirects, you need to edit the.htaccess file first. Before making any changes, make sure to backup the original file. If you accidentally make a mistake while editing the file, it can damage your entire site. Therefore, it is recommended to download the original file via FTP to have a backup of the file. This way, if you do make a mistake, you can upload the backup to avoid any issues and correct the errors.
Please note that editing the file is only possible if you have an Apache server.
Now, let's see how to edit redirects by editing the file.
In this example, all you need to do is adding the new location to the file by using the following code:
Redirect 301 /oldpage.html http://www.yoursite.com/newpage.html
Redirect 301 /oldpage2.html http://www.yoursite.com/folder/
This will move one page or one directory to the new destination. For example, if you want to move your entire website to the new destination because you’ve changed your domain name, add this to your.htaccess file:
Redirect 301 / http://newsite.com/
This will maintain your links intact so http://www.oldsite.com/hello-world will become http://www.newsite.com/hello-world.
You can also use PHP itself to redirect a page. If you ever find yourself needing to redirect a PHP web page that isn’t part of your WordPress installation, all you have to do is add this line to your header:
[php]header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.yournewwebsite.com");[/php]
Search engines need to know that this is a permanent 301 redirection. This is why it’s important to add the line “moved permanently” to your header file. This line should also be placed at the top of the header file to ensure the redirection works correctly.
Adding redirects using a plugin
As always, there are plugins you can use to add a redirect. Redirection is one of the top plugins for this purpose. It may seem a bit intimidating at first, but it's worth taking a few minutes to familiarize yourself with.
To add a redirect, all you have to do is set the source URL (the one that's giving you the 404 error) and enter the right link in the destination URL field (as shown in the screenshot below).
The statistics page is one of my favorite features of this plugin. It allows me to track the number of times a particular link is accessed, the number of times someone tried to access that link, where that person found that link, and the last time it was accessed.
If you want to see the number of clicks on a particular link, you would need to enter that link as a redirect and then set that plugin to not do anything. This is a great way to track the amount of clicks on a download link or even on an affiliate link!
Another great feature of the plugin is that you can organize your redirects. For example, if you want your users to see an affiliate link at the bottom of your blog, you can set it up as an affiliate link under "ugly affiliate link" and group it under "affiliate link here".
There is also a premium version of this
plugin called 301 Redirect Manager by WebFactory Ltd.
Alternatively, you can use a plugin specifically created for the purpose of redirecting affiliate links, such as the ThirstYAffiliates plugin.
One thing to keep in mind when using this Redirection plugin is that you should turn off log tracking in the settings. Log tracking can add a lot of extra work to your server.
Other types of redirects
In this tutorial, we have focused on 301 redirects, which are also referred to as permanent redirects. However, there are other redirect types that are considered temporary redirects.
Generally, temporary redirects are used more in ecommerce sites, especially when products stop working.
Search engines can be told that a URL is temporarily unavailable.
Moz has a great article that explains this in more detail.
Conclusion
There are a few different ways to add a redirect in WordPress. The most common method is to add them manually using the.htaccess file, which minimizes the effect on your server. However, if you choose to use a plugin, it will be much simpler.
By adding redirects correctly, you can improve your search engine optimization (SEO), revive old posts, and make sure your visitors have a great experience on your site.