501

I am working on a web application that is using redirects (for pretty URLs).

I am trying to debug logic in the way the redirects are working. However Google Chrome keeps remembering the redirects and even after I change the code, redirecting the same way.

This is making it very hard to troubleshoot.

For example if I redirect /this to /that, then change my code to NOT redirect /this anymore. Google Chrome is still redirecting to /that. Like the redirect is cached or something. Is there a way to turn this off?

JD Isaacks
  • 8,674
  • 12
  • 42
  • 41

21 Answers21

367

Google Chrome will cache your 301 redirects. To get around this, and to keep the tabs open, you'll just need to clear your browser cache.

Chrome Menu Chrome Menu > Settings > Show advanced settings... > Privacy > Click Clear browsing data...

Whatever else you select, make sure "Cached images and files" is a checked option.

Then click Clear browsing data and you should be able to retest again.

If you've just followed the redirect, you only need to delete data from the past hour.

Alternatively, test and develop in incognito mode. There the cache is flushed after the browser is closed.

Windos
  • 11,235
random
  • 15,201
227

This is the sure proof way to clear Chrome's sticky memory for redirects (not only temporary/302 but also the permanent/301 ones) without clearing all your browsing data (method used by the current top answer):

  1. Open the Developer Tools panel (optioncommandi on Mac, or ctrlshifti on Windows)

  2. Click and hold the reload icon enter image description here

  3. A menu will open

    enter image description here

  4. Choose the 3rd option from this menu ("Empty Cache and Hard Reload")

Here's an excellent explanation of how these 3 options differ.

PS: To avoid having to do these steps everytime the redirect is followed by Chrome: check disable cache in DevTools, and while DevTools is open Chrome will bypass the redirect cache (per this answer)

Gaia
  • 7,279
  • 8
  • 38
  • 40
130

It's not a perfect solution, but I was able to prevent Chrome from using the cached redirect by passing a bogus query string, or adding a bogus parameter to the existing query string. For example, adding a simple ? to the end of a URL that didn't have q query string worked for me on Chrome 30 on Max OS X.

sradack
  • 1,401
97

There's a "wontfix" Chromium bug about this,

That is the expected behavior.

Note that:

  1. You can add cache control headers to a 301 and we'll follow them (expiration etc)
  2. If the resource in question is a subresource, reloading the page will cause the redirect to be re-validated with the server.
  3. You don't have to lose your entire cache. Just follow the redirect and delete the last hour.
dbr
  • 5,147
75

If you have the "Disable cache (while DevTools is open)" option enabled in the DevTools, then simply having the DevTools open is enough to bypass the redirect cache, without constantly throwing away your session.

27

Chrome caches HTTP redirects and stop checking with the site if the redirect has changed. This can be frustating, since the easiest way to fix (visiting the site and forcing a hard refresh) can't be used because the redirect will happen before you access the link. This is a won't fix issue.

To workaround this, you can clear your browsing data, as explained here or you can follow the steps below and avoid losing your history.

  1. Open the Chrome Developer Tools dev-tools

  2. Click in Settings settings

  3. Check Disable cache (while DevTools is open) disable

  4. Visit the site that you wanted and the cache problem will be solved.

Zanon
  • 419
17

Go to chrome://net-internals and at the far right open the drop-down and choose "Clear Cache". As of version 48, this was the only thing that worked for me to clear a cached 301 (permanent redirect).

Update: Unfortunately, as of version 71 (Dec 2018) Google has removed the net-internals feature.

10

To clear the redirect cache for a single page in Chrome, View Source and do a hard refresh (CTRL + SHIFT + R).

This works as the source browser doesn't automatically follow the 301 redirects.

7

.dev domains are forced to use HTTPS on Chrome 63+

Since Chrome 63, out December 2017, all domains ending on .dev (and .foo) are forced to use HTTPS via a preloaded HTTP Strict Transport Security (HSTS) header.

More on it here: https://ma.ttias.be/chrome-force-dev-domains-https-via-preloaded-hsts/

7

In either Chrome or Firefox, you can refresh the redirect by typing "view-source:redirect.yoursite.com" and hitting enter. Then, refresh that page. Now, that should force Chrome or Firefox to refresh the redirect.

mrbofus
  • 91
6

As described here could be caused by HSTS

To get around this, I did the following.

In the Chrome address bar type "chrome://net-internals/#hsts" At the very bottom of a page is QUERY domain textbox - verify that your site (localhost e.g.) is known to the browser If it is, DELETE the localhost domain using the textbox above Your site should now work using plain old HTTP

Tonino
  • 169
5

For develop purpose i recommend you in Chrome open DevTools settings and check "Disable cache". Then 30x redirects are not cached and you can debug .htaccess files and so on! enter image description here

lukyer
  • 151
4

If you just want to check the redirects are working as expected it's probably easier to use a command line tool like wget or similar. You can inspect the response headers and redirects are not cached.

3

I tried all answers on this page but none worked until I ran flushdns on windows command line window.

C:\Users\DBashyal>ipconfig /flushdns

Windows IP Configuration    
Successfully flushed the DNS Resolver Cache.

FYI, I already had Disable cache checked as mentioned in this answer.

1

If you don't want to lose your entire cache and your redirect is still stuck in cache, you could try visiting the view-source: version of the url. That refreshed the redirect cache of the same url for me.

1

If you want a simple button that you can tick on or off to permanently disable Chrome cache, then check out this plugin: CacheKiller.

Automatically clear your browser cache before loading a page. Can be enabled/disabled with a single mouse click.

There is nothing wrong with any of the other answers, it's just that having a simple on/off switch right on the browser is super convenient.

1
  1. Go to chrome://settings/search#clear%20browsing%20data

  2. Click "Clear browsing data"

  3. Check "Cached images and files" (and uncheck the rest if you want)

  4. Click "Clear browsing data"

enter image description here

the
  • 2,929
1

simplest method, hard refresh. hold Ctrl + R a few seconds. This clears redirects as well as static resources.

0

If you can control the page and if you don't want browsers to cache the page then the correct way is to add the following header:

Cache-Control: no-cache 

But just doing this won't immediately work, since the browser is still loading from the cache; after doing this change, follow this answer to reload the page: https://superuser.com/a/924748/100398

Caner
  • 206
  • 1
  • 4
  • 11
0

In my case the cache was kept and I've got 307 Internal Redirect (from disk cache) because one of the extensions. If it works in incognito (without extensions) you can try disabling extensions and apply from the solutions above.

See more at How to clear 307 internal redirect (from disk cache) on Chrome

-1

Incognito Mode (CTRL + SHIFT + N)

There are amazing answers already to this question, but I'm lazy and really was just testing something out, so I tried the Incognito Mode in Chrome and the url was not redirected. I guess every time you use it all the caches start from a clean state!

This "feature" is really a pain, I thought my web server was misbehaving when it was actually the browser.

I'ts funny that I used IE to find out that Chrome was playing me!