How to Clear the 301/302 Redirection Cacheโ€‚by@epranka

How to Clear the 301/302 Redirection Cache

image
Edvinas Pranka HackerNoon profile picture

Edvinas Pranka

Software engineer

I think many web developers and server administrators had been facing the 301 redirection cache. I had facing it very often until I learn the lessonโ€ฆ
I hope it helps you and you learn something from me, not from your mistakes ๐Ÿ’ฅ

๐Ÿ‘‰ For example, when you configure the SSL certificate and make the 301 redirection from HTTP to HTTPS, but something goes wrong, you donโ€™t have the ability to enter the HTTP version again. Browser caches the 301 redirection and redirects you to HTTPS.

๐Ÿ‘‰ The second example is when you changing the website domain. If you redirect from the old domain to the new domain with the 301 redirection, browser caches it too, and preventโ€™s you to enter the old domain.

๐Ÿ‘Œ How to avoid that? Use the 302 redirection as long as everything works as it should. Then, and ONLY then, change the 302 redirection 301. Why? โ“

๐Ÿ“š The definition of 301 and 302 redirections:

301ย โ€” means that the resource (page) is moved permanently to a new location. The client/browser should not attempt to request the original location but use the new location from now on.

302ย โ€” means that the resource is temporarily located somewhere else, and the client/browser should continue requesting the original URL.

The 301 is a permanent redirection. Even if you remove the redirection from the server, your browser continuously redirects the resources to the new domain or HTTPS, because of the hard cache.

So the 302 is not hard cached by the browser and you have the ability to access the old version if you remove the redirection from your server (website).

๐Ÿ’€ How really dangerous is the 301 in production? It is very simple. If something goes wrong and you release the 301 redirection to the production, your clientโ€™s browsers permanently cache this redirection and you will have to tell all the clients to clear the browser cache. This is a ๐Ÿ’ฉ

๐Ÿค” Okay, what I can do if my browser caches the 301 redirection? Every website developer know the Chrome Developer tools (F12) and a Right-Click on the Refresh button

image

๐Ÿ˜Ÿ But I can tell you that is not enough. Suppose you badly redirected the old domain to the new domain with the 301 redirection and you want to clear the domain cache. You must do it on the old domain because the old domain is redirecting. But you canโ€™t access itโ€ฆ The only thing to do is to clear the whole browser cache and even cookies, but no one wants to do it.

๐Ÿ˜Ž There is a trick on how you can access the old domain (or any redirecting URL).

  1. Before going to the website open the Chrome Developer tools (F12).
  2. Go to Network tab
  3. Check theย Preserve logย checkbox
  4. Clear the log
image

๐Ÿš€ Now enter your old domain URL and navigate to it. Of course, it will be redirected to the new domain. But in your Network log, you will have the old domain redirection request and you will have the ability to clear the domain cache by clicking the request with Right-Click and select the Clear browser cache. After that, your 301 redirection will be removed. But please remember that you must remove the redirection from your server before.

image

In the screenshot above I redirecting the non-www to the www domain.

โค๏ธ Thanks for reading this. I hope it was helpful to you. Feedback and questions are appreciated.

๐Ÿ™ Follow onย Twitter,ย GitHub, and letโ€™s connect onย LinkedIn

Previously published at https://dev.to/epranka/clear-the-301-302-redirection-cache-chrome-4dio

Comments

Signup or Login to Join the Discussion

Tags

Related Stories