We’ve all been there. You click on a link or type in a URL in your browser and end up on a page with a 404 error. Not a great experience, right? This happens because the web page you were looking for does not exist anymore or was moved to a new location.
As a website owner, it is your responsibility to fix these issues on your website that will not only frustrate your visitors but will also have a negative impact on your site SEO.
Luckily, you can easily fix this with redirects. If you are not sure how to create one, don’t worry, we’ve got you covered. In this article we will explain when you should use redirects and how to create them by using two different methods:
- By using plugins, and
- Configuring the .htaccess file.
What is a WordPress redirect and how does it work?
A URL redirect is a web server feature that sends a visitor from one URL to another. There are various different types of redirects, but we will only talk about the 301 redirect here, which is by far the most important. A 301 redirect is a permanent redirect that will automatically transfer all visitors and search engines to the new location.
Why are 301 redirects important?
When you move your website to another domain or a web page to a new location (permalink in WordPress), it is crucial you create a 301 redirect. A redirect allows visitors and search engines to reach the new URL by using the old one. This ensures visitors get access to the content they were looking for and prevents broken links on your website.
Broken links can be harmful to your website in many ways:
- Visitors can’t access the content they wanted. It leads to bad user experience and ultimately visitors leaving your website.
- Search engines can not crawl this URL anymore. All the link juice you gained on this URL will be lost.
- If your website has lots of broken links, it can seriously impact your website search rankings.
Redirects will solve all of these issues and help you maintain the backlink strength of your old page and transfer the traffic to the new page.
When do we use WordPress redirects?
It’s very important to create redirects when:
- You remove a post or page and you want visitors to visit a new post or page instead.
- You change the permalink of a post or page.
Now that you know the why and when of redirects, let’s take a look at how you can actually set up redirects in WordPress.
Create redirects with plugins
This is the easiest approach and one that is recommended for WordPress users that don’t have the technical knowledge needed for web server configuration. One of the simplest plugins for managing redirects is the Redirection plugin. It will allow you to set up redirects in a matter of minutes and help you keep track of the 404 errors on your WordPress website and fix broken links.
As with any plugin, you need to install and activate it first. Once activated, visit Tools > Redirection. To set up a simple 301 redirect, all you need to do is enter the source URL – the URL of the old page that doesn’t exist anymore, and the target URL – the URL of the new page where you want visitors to be redirected to. Hit the Add Redirect button and that’s it! Easy peasy!
If you have many redirects, you can also group them for your convenience. For advanced configuration click on the gear icon next to the Add Redirect button. A new set of options will appear to change the type of redirect, how it should match the URL and so on. However, in 99% of the cases simple setup will suffice.
Setting Up 301 Redirects in WordPress using .htaccess
You can also set up redirects by adding code to your .htaccess file which is a web server configuration file. However, this method is only recommended for those who are comfortable with a little bit of coding as messing with the .htaccess file can break your WordPress website.
Important note! Before you do any changes to your .htaccess file, it is very important you back it up first. You can download it to your local computer, so if something goes wrong you can override the broken .htaccess file with the old version to restore your website.
So if you’re happy to do a little bit of coding here is what you need to do:
- Connect to the web server using an FTP client. If your web server has a control panel (e.g. cPanel) installed you can use the file manager instead.
- The .htaccess file can be found in the root directory of your WordPress installation. Edit it by using a simple editor like Notepad or directly in the file manager of your web hosting control panel.
- Add the code below to your .htaccess file, preferably to the end of it. Replace the URLs with your own and you are good to go.
- Save the file and upload it to the server.
RewriteEngine On Redirect 301 /old-post-url/ http://yoursite.com/new-post-url/
That’s it! Your redirects should be set up correctly now. Just remember to check for your 404 errors regularly and set up redirects accordingly.
Is fixing broken links part of your website maintenance routine? Feel free to share with us how you tackle this issue in the comment below.