Use AWS ALB Fixed Response instead of Redirect to avoid Browser 301 redirect caching

Rommel Baltazar
2 min readNov 19, 2020

--

AWS Application Load Balancers has a feature to redirect requests. However, redirect should only be done when the change is permanent while Fixed Response can be employed when the change is temporary.

The reason for not using redirects for temporary change is the following from https://www.ryadel.com/en/clear-google-chrome-redirect-cache-for-single-url-page-howto/:

As you most likely known since you found this post, Google Chrome — just like most other browsers — implements the 301 redirect caching, meaning that it will often locally cache the HTTP 301 redirects for a given amount of time without asking the server another HTTP response for that same URL.

This is a perfectly fine behaviour, as it’s explicitly allowed by the RFC 7231 Section-6.4.2, which says the following:

A 301 response is cacheable by default; i.e., unless otherwise indicated by the method definition or explicit cache controls (see Section 4.2.2 of [RFC7234]).

The only downside of that is that, whenever you’re testing or developing a web site (or a web server such as IIS or NGINX) and temporarily configure a HTTP 301 that you want to change later on, you could run into that redirect for a long period of time, thus being unable to access the previously-301 URL, page or resource.

The most common redirect use-cases are following:

  1. An application/website is shutting down and all requests to it should be redirected to another application/website.
  2. Redirect http to https

These use-cases are permanent changes. For the first use-case, reverting the change will lead a user to experience the browser caching issue. Imagine if you implement this to a production website — you will have users being redirected even if you have removed the setting in AWS ALB and you will need to instruct each user to clear their cache (not ideal).

For a temporary change like when wanting to redirect requests to a “Maintenance website” users while upgrading an application, AWS ALB Fixed Response can be used instead. With Fixed Response, you can write your own HTML and it will be served when a user visits the site. An example configuration is as below:

After removing this configuration, users should be readily redirected back to the original application.

--

--

Rommel Baltazar
Rommel Baltazar

No responses yet