惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Engineering at Meta
Engineering at Meta
博客园_首页
H
Help Net Security
WordPress大学
WordPress大学
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
罗磊的独立博客
博客园 - 三生石上(FineUI控件)
B
Blog
I
InfoQ
SecWiki News
SecWiki News
T
Tailwind CSS Blog
Spread Privacy
Spread Privacy
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
Vulnerabilities – Threatpost
N
Netflix TechBlog - Medium
P
Palo Alto Networks Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Vercel News
Vercel News
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
K
Kaspersky official blog
M
MIT News - Artificial intelligence
S
Schneier on Security
T
Threat Research - Cisco Blogs
F
Fortinet All Blogs
Cyberwarzone
Cyberwarzone
Scott Helme
Scott Helme
aimingoo的专栏
aimingoo的专栏
Martin Fowler
Martin Fowler
MyScale Blog
MyScale Blog
The Cloudflare Blog
Recent Announcements
Recent Announcements
Security Latest
Security Latest
G
GRAHAM CLULEY
IT之家
IT之家
Y
Y Combinator Blog
The Last Watchdog
The Last Watchdog
腾讯CDC
Google DeepMind News
Google DeepMind News
V
V2EX
S
Securelist
TaoSecurity Blog
TaoSecurity Blog
B
Blog RSS Feed
S
SegmentFault 最新的问题
博客园 - 叶小钗
P
Proofpoint News Feed
云风的 BLOG
云风的 BLOG
Project Zero
Project Zero
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
F
Full Disclosure

How to Guides Archives - GTmetrix

How to Connect the GTmetrix MCP With Claude - GTmetrix How to Connect the GTmetrix MCP With Codex - GTmetrix How to Connect the GTmetrix MCP With GitHub Copilot CLI - GTmetrix How to Connect the GTmetrix MCP With ChatGPT - GTmetrix How to Connect the GTmetrix MCP With Cursor - GTmetrix Introducing GTmetrix MCP: What It Is, How It Works, and Why It Matters - GTmetrix Image Optimization With Imagify Using GTmetrix History Exports in Google Sheets WordPress Optimization Using WP Rocket WordPress Optimization Guide How to properly size images
How to avoid multiple page redirects
Varun · 2020-11-17 · via How to Guides Archives - GTmetrix

Understand why you should minimize URL redirects, wherever possible, and identify the best practices to set up URL redirects.


Overview

In our audit documentation, we touched upon the fact that redirects can significantly affect your website’s performance.

In this article, we’ll explain in detail about how to optimally set up redirects for your website.
 


Redirection Best Practices

In general, try to avoid redirects as much as possible.

If, however, you cannot avoid them for whatever reason, GTmetrix always recommends URLs be redirected on the server-side as they are fast, cacheable, and can be implemented universally.

To this end, follow these best practices to ensure optimal use of redirects:
 


 

1) Favour Server-side (web-server or application), vs Client-side (HTML, or JavaScript) redirects

When dealing with server-side redirects, we recommend that they be executed via web server configuration as they are often faster than application-level configuration.
 

Server-side redirects happen immediately and help visitors reach their final destination sooner.


 

However, if the application itself is fast and optimized for performance, application-level redirects can be executed.


 

2) Say no to client-side redirects

Avoid client-side redirects, as much as possible, as they are slower, non-cacheable and may not be supported by browsers by default.
 


 

3) Avoid landing page redirects/Minimize redirect chains

Wherever possible, avoid landing page redirects; especially, the practice of executing separate, individual redirects for reasons such as protocol change, adding www, mobile-specific page, geo-location, and subdomain.

Always redirect to the preferred version of the URL, especially, when redirects are dynamically generated. This helps eliminate unnecessary redirects.
 

An example of an optimal redirect, going directly from http:// to https://www


 

For instance, if a website has both site.com and www.site.com, set up the redirect to directly forward from http://site.com to the preferred https version of the new URL (in this case https://www.site.com). This helps you skip an intermediate step in the redirect chain.

As a general rule of thumb, try and limit the number of redirects to 1, wherever possible.
 


 

4) Periodically review your redirects

Review the redirects in place from time to time to ensure that old and irrelevant redirects are removed.

An example of a long redirect chain.

Similarly, remove temporary redirects if not needed anymore.
 

Remember that combining multiple redirects into a single redirect is the most effective way to improve web performance.
 
 

A brief note on HTTP Strict Transport Security (HSTS)

HSTS is a response header that commands the browser to only load the HTTPS version of a website, ignoring any attempt to load the unencrypted HTTP version.

Here are a few key reasons why your website should be HSTS-enabled:

  • It provides an extra layer of security to prevent data-theft and phishing attacks. It also eliminates an unnecessary step in the redirect chain to improve web performance.
  • It’s supported by most modern browsers and references a pre-load list to verify that websites are HSTS-enabled.

However, be aware of possible HSTS downsides, such as:

  • If you have legacy configurations that are not equipped for HTTPS, they will break.
    • Only use the includeSubDomains directive when all subdomains are properly set up for HTTPS with the required SSL/TLS certificates.
  • Inclusion in the preload list cannot be easily undone.
    • To prevent the delayed removal of your website from the preload list, do not include the preload directive by default.

 
Learn more about HSTS and the preload list here.


Setting up redirects

The following are some basic guidelines for optimally executing redirects on various server types :
 


 

For Apache

To setup URL redirects, you’ll need to edit the .htaccess file as it allows overwriting of the central configuration at the directory level. We recommend that you create a backup of the original .htaccess file before you modify it.

Note that .htaccess files may be hidden, so make sure that any ‘Show hidden files’ options are enabled.

Refer to this article for comprehensive details on redirection using .htaccess files.
 
 


 

For NGINX

In NGINX, redirects are handled using a .conf file, namely the nginx.conf file, located in the /etc/nginx/ directory.

To execute NGINX redirects, follow the instructions in this article and modify the code as necessary.
 
 


 

For IIS

For the Microsoft IIS Server, follow the instructions in this Microsoft document to set up URL redirects for your website.


Summary

Avoiding multiple page redirects is one of the most important audits to optimize as redirects, by their very nature, can affect web performance and cause a poor page experience for your users.

Always try and avoid redirects as much as possible; however, remember that they may be unavoidable in many cases as site functionality may depend on them.

If you must execute redirects, follow some of the best practices – such as executing them server-side, combining multiple redirects into one, minimizing redirect chains, and periodically reviewing your redirects to remove unwanted redirects.

Depending on your web server, follow the appropriate instructions to optimally set up redirects for your site and then test your page using GTmetrix to see how much they improve your web performance!


Keep your site’s performance at the top of your mind

PRO Monitoring Splash

Get more On-Demand Tests, Monitored Slots and Advanced Analysis Options, along with Hourly Testing, with a GTmetrix PRO plan.

Other features include: Priority queue access, Mobile Testing, Remote Location Monitoring (including Premium Locations), and more!


Upgrade to PRO today!