http

Introduction

When configuring redirects on a website, especially in the following scenarios, issues can arise:

Redirecting from HTTP to HTTPS: Suppose you’ve set up an SSL certificate to upgrade your website from HTTP to HTTPS. If problems occur during this process, rendering the site inaccessible, you might consider reverting to the HTTP version. However, the challenge arises once a permanent 301 redirection is in place. Even if you remove the redirection on the server, browsers retain this information. Consequently, users’ browsers continue to enforce the HTTPS redirection, preventing them from accessing the HTTP version.

Changing the Website Domain: When migrating a website from one domain (such as old-domain.com) to another (such as new-domain.com), a permanent 301 redirection is often employed. This informs search engines and browsers that the site has permanently moved to a new domain. However, if complications arise during this process, you may wish to undo the redirection, allowing users to access the old domain again. Unfortunately, due to browser hard caching of 301 redirections, users become permanently redirected to the new domain, unable to revisit the old one.

To avoid such situations, it is advisable to use a temporary 302 redirection initially, ensuring everything functions correctly. Unlike a 301 redirection, a 302 redirection is not permanently cached by browsers. This means that if necessary, you can revert the redirection without users being permanently locked into the new URL. This approach eliminates the need for users to manually clear their browser caches, enhancing the overall user experience.

  • 301 Redirection: Indicates that a resource (page) has permanently moved to a new location. The client/browser should not attempt to request the original location but use the new location from now on.

  • 302 Redirection: Indicates that the resource is temporarily located elsewhere, and the client/browser should continue requesting the original URL.

A 301 redirection is permanent, meaning that even if removed from the server, browsers will perpetually redirect resources to the new domain or HTTPS due to hard caching.

On the other hand, a 302 redirection is not hard-cached by browsers. If you remove the redirection from your server (website), you can still access the old version.

Clearing 301/302 redirection cache typically involves clearing browser cache or the operating system’s DNS cache. Here’s how to do it on different platforms:

Clearing Browser Cache (Applicable to Windows, macOS, Linux)

Google Chrome:

  1. Open the Chrome browser.
  2. Click the three vertical dots in the upper right corner and select “More tools.”
  3. Choose “Clear browsing data.”
  4. In the popup window, select the “Advanced” tab.
  5. Set the time range to “All time.”
  6. Check the “Cached images and files” option.
  7. Click the “Clear data” button.

Mozilla Firefox:

  1. Open the Firefox browser.
  2. Click the three horizontal lines in the upper right corner and select “Privacy & Security.”
  3. In the “Cookies and Site Data” section, click “Clear Data.”
  4. Ensure the “Cache” option is checked.
  5. Click “Clear.”

Microsoft Edge:

  1. Open the Edge browser.
  2. Click the three horizontal dots in the upper right corner and select “Settings.”
  3. Scroll down and click “View advanced settings.”
  4. In the “Privacy and services” section, click “Clear browsing data.”
  5. Check the “Cached images and files” option.
  6. Click the “Clear” button.

Clearing Operating System’s DNS Cache (Applicable to Windows, macOS)

Windows:

  1. Open Command Prompt (search for “cmd” in the Start menu and open it).
  2. Enter the following command and press Enter:
    ipconfig /flushdns

macOS:

  1. Open Terminal (find it in Applications > Utilities folder).
  2. Enter the following command and press Enter:
    sudo dscacheutil -flushcache
    Then enter your administrator password and press Enter again.

Please note that clearing browser cache might lead to loss of login sessions on websites. Ensure you have backed up essential information in case you need to log in again.


Note: This article is a translated version of the original post. For the most accurate and up-to-date information, please refer to the original source.
```