Chances are that you have just tested your website speed on GTMetrix or Pingdom and it suggests you to minimize redirects. In this post you will understand what causes this issue and how you can fix it quite easily.
What is a WordPress Redirect?
A redirect is when WordPress sends both users and/or search engines to a separate URL from the one it was originally supposed to go to.
Types of Redirects
301 – Permanent Redirect
This is used to inform the search engines that the page location has permanently moved. Most probably this is the only redirect that you have heard of and it is the only one you will ever need.
302 – Temporary Redirect
As the name suggests, this is used to tell search engines that a page location changed temporarily.
303, 307, 308… You can read more about them here.
What causes a Redirect in WordPress?
There are numerous reasons that can cause a redirect to happen. Here is the list of the most common ones:
SSL certificate – http:// to https://
WWW to non-WWW (or vice-versa) – Depending on whether you have www prefix or not.
Updated Page/Post – This is used when you need to redirect the old version of a post to the latest updated version.
Automatic redirects – WordPress is smart enough to take the user to the right URL even when there is a minor typo in the URL.
Changes in Site Structure – If a change in site structure has caused the permalinks to change then old URL’s need to be redirected to new ones. This kind of redirect due to change in permalink structure can be avoided by using the plugin – Change Permalink Helper
How do redirects affect page speed?
Well, you must have understood that redirects are needed for the proper functioning of your website, however it is even more important to realize that redirects dramatically increase page load speed.
Lets look at an example to get a clear picture of this.
Server Requests with Redirect
Server Requests without Redirect
As seen from the above screenshots the load on the server is drastically higher when there is a redirect rather than when there isn’t one. Google has made it clear that they prefer sites having a fast load speed and don’t forget users too!
Thus minimizing redirects in WordPress is of utmost importance.
How do I check for redirects?
At this point you are probably wondering how do I find existing redirects on my website. For that you can simply use the following tool named Redirect Mapper. Just enter your URL and it will display redirects from both www and non-www
versions of the url entered using both http and https.
Ideally you should have less than or equal to 1 redirects in each column and atleast one column with 0 redirects,
How to Minimize Redirects in WordPress (the solution)
There are a number of ways to fix this problem depending upon where your site is hosted.
The solution is quite straightforward incase you are using Cloudflare on your website (which you must!)
Incase you do not intend to use Cloudflare for some reason then first of all it would be useful to find out whether your web server uses Apache or Nginx.
I am sure you are confused right now but don’t worry, I will tell you a simple way to find out whether your web server uses Nginx or Apache.
- Visit your website in Chrome.
- Right click anywhere and click on inspect.
- A panel will open in the bottom of your screen, go there and click on the Network Tab.
- Refresh the page once.
- Click on the URL of your website in the Name column.
- Your server is clearly stated in the Response Headers as shown in the screenshot below.
If you use Cloudflare
- Login to your Cloudflare Account, Select your website and click on SSL/TLS -> Edge Certificates.
- Turn off Always Use HTTPS
- Add the following page rules
Rule 1
If the URL matches - http://example.com/*
CLICK "+ A Setting" and select "Forwarding URL"
Select Status Code - "301 Permanent Redirect"
Enter Destination URL - https://example.com/$1
CLICK Save and Deploy
Rule 2
If the URL matches - www.example.com/*
CLICK "+ A Setting" and select "Forwarding URL"
Select Status Code - "301 Permanent Redirect"
Enter Destination URL - https://example.com/$1
CLICK Save and Deploy
If you use Apache
If your site is powered by Apache, then you will have to add URL rewriting rules to the .htaccess file of your website. You might have to select the option to show hidden files in your cPanel incase you are unable to see the file there.
If you are using the www version for your site then add the following code:
#Force www:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^wpintensity.com [NC]
RewriteRule ^(.*)$ //wpintensity.com/$1 [L,R=301,NC]
If you are using the non-www version for your site then add the following code:
#Force non-www:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.wpintensity.com [NC]
RewriteRule ^(.*)$ //wpintensity.com/$1 [L,R=301]
Important!
- Do NOT add both the snippets of code to your htaccess file. Select only one as per your website version.
- Replace wpintensity in the above snippets with the domain name of your website.
If you use Nginx
Nginx powers more advanced hosting configurations, hence in this case, minimising redirects is not as simple. The way in which this can be configured varies from host to host, and it will be suitable for you to get in touch with your hosts’ tech support team.
Conclusion: How to Minimize Redirects in WordPress?
I hope this article was useful in terms of helping you minimize the redirects you have on your WordPress site. Atleast you now have one less factor to worry about in the Pingdom Website Speed Test.
Feel free to comment below incase you have any queries or difficulties.
R Ramesh sharma says
your article was helpful
thanks for it !
jojo says
Very helpful! Thanks!
heri says
yes , minimize redirect- this problem in my website . thanks for sharing