Do you want to manage 301 redirects and keep track of 404 errors in WordPress? In this beginner’s guide you will learn everything about creating redirects in WordPress.
What is a redirect?
Redirects are used to send website visitors from one address to another. This allows a visitor’s browser to automatically point them to the right address.
For example, a redirect has been placed on www.wplounge.be to our Dutch WordPress blog www.wplounge.nl so that visitors end up on the correct website.
There are various types of redirects, such as a 301, 302 and 307. But first let’s take a look at different reasons for creating redirects.
Why would you redirect one page to another? There are several reasons that are further explained in the examples below.
In case you have moved your website to another domain, make sure to redirect your old domain to the new one. Not only does this send your visitors to the correct domain, it also tells search engines that your website has been moved.
A website, including pages and posts, builds a certain “value” or “authority” in the search engines. These are, among other things, based on the amount of backlinks that point towards your website. If you don’t create a redirect from your old domain to the new domain, it will surely decrease in value which will affect your rankings.
You can easily create a redirect when you move your website one-on-one and if all pages remain the same. Simply redirect your whole domain name and you’re done. In the table below, you can find an example:
|Old URL||Redirect to:|
A non-existent page
If links point to non-existent pages, you should redirect them to existing pages. This is often used when an article has to be re-written. If you don’t want your article to loose its rankings, you should point the old page towards the new one.
With or without www
Not all websites have www. included in the domain name. To prevent your website from being located on two domain names, for example wplounge.org and www.wplounge.org, you should point your visistors from one to another.
If you go to www.wplounge.org, you will automatically be transferred to wplounge.org (without www). This can be adjusted in the WordPress admin. Go to Settings > General and you’ll see the following options:
Another example of a redirect is the URL shortener. This shortener can be quite useful for sharing articles on social media channels such as Twitter. Many websites have their own URL shortener. For example, thenextweb.com uses a custom domain name for shortening URLs: tnw.co.
Types of redirects
There are different types of redirects. The 301 redirect (301 Moved Permanently) is a HTTP response code and is used (most) often. When a page functions properly, it indicates a “200” code which stands for “OK”.
HTTP response codes
Let’s take a look at different types of HTTP response codes. The response code you (most likely) know is the “404” code, which means “ERROR PAGE NOT FOUND”. There a different kinds of response codes:
- 4XX codes (e.g. 404) indicate an error.
- 2XX codes (e.g. 200) indicate “successful”
- 3XX codes (e.g. 301) are used for redirects
When to create a 301 redirect (Moved Permanently)
You should use 301 redirects when the website, page or post has been moved and you want to point visitors towards a new address instead. If you don’t, it will cause your visitors to see a 404 ERROR PAGE NOT FOUND alert. This will also impact your website’s optimization and thus badly influence your search engine rankings. You should use 301 redirects when you are planning to delete an article for fresh new content or when you want to change the permalinks of your article.
When to create a 302 redirect (Moved Temporarily) – old!
302 redirects are temporarily redirects that don’t obtain value by the search engines. In most cases, these redirects are not used because they are considered deprecated redirects. Although you can still use them, it is strongly recommended to use 307 redirects instead.
When to create a 307 redirect (Moved Temporarily)
Since HTTP 1.1, the 302 redirect has been replaced by the 307 redirect. 307 redirects are used when a redirect is only temporary. In this case, temporary means “a couple hours” and not “a couple weeks”. You can transfer visitors to a “maintenance page” by using 307 redirects during the maintenance of your server.
Now that you know the different types of redirects, it’s time to create redirects. In most cases, you will need a 301 redirect.
An easy way to create a redirect is by going to the control panel of your webhosting provider (e.g. DirectAdmin). Under “Advanced Features” in DirectAdmin you can find the option “Site Redirection“.
A new screen will pop up when you click on it. Take a look at the following redirect example:
If I would save https://wplounge.org/wplounge-redirect/ as a redirect, it will send visitors to https:///www.wplounge.org/. When you leave it empty or add “/”, the whole domain will redirect to the URL you filled in underneath.
As you can see, you can easily make 301 redirects from DirectAdmin. However, watch out that you don’t lose sight of all the redirects you make.
There are many types of redirect plugins available for WordPress. Redirection is used most often as a redirect manager for WordPress. The most convenient feature, is that the plugin also reports 404 pages. This means you can quickly anticipate and add redirects to 404 pages.
Another plugin you can use is called the Yoast SEO. However, you will have to purchase Yoast SEO premium plugin. This plugin can automatically detect 404 pages through its connection with Google Search Console. Furthermore, it includes a built-in redirect manager that can help you solve 404 errors. The plugin also informs when you are about to create a page that redirects back to itself, also referred to as “Redirect Loops“.
You can also create redirects in the .htaccess file which you can find in the WordPress site’s root directory. You can reach this location and edit the .htaccess file by connecting you website to your FTP client. If you can’t find the .htaccess file in WordPress site’s root directory, you should (most likely) force the FTP client to show hidden files.
The .htaccess file will now be visible. Right click and edit so that WordPress is allowed to edit the file.
A redirect is a .htaccess file that you can edit in a plain text editor such as Notepad. Here you can see what such a redirect looks like:
Redirect 301 / https://new-URL.com
The code above redirects every URL to a new website/domain name. If you want to redirect only one specific page, you can use the following code:
RedirectMatch 301 /blog(.*) https://new-URL.com$1
There are several important aspects to look at while creating redirects in WordPress.
Prevent double redirects
Make sure to avoid double redirects. Double redirects are present when one URL points to an URL that also points to another URL. Prevent this from happening because it decreases the value of your website.
Prevent redirects to 404 pages
Prevent redirection to a non-existent page. This could negatively influence your website’s value in the search engines, thus affecting your rankings.
Prevent redirect loops
Redirect loops, as explained earlier, are present if one page redirects back to itself. This could possibly happen via other pages, leading to an infinite sequence of redirects. Luckily, many web browsers, such as Google Chrome, notice this automatically and will inform you about it.
Also, check out Google webmasters’s Youtube video (Google Webmaster) on 301 redirects: