How can I make Chrome stop caching redirects?

427

64

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

Posted 2011-06-30T17:05:28.303

Reputation: 7 224

1Entering a new www.mywebsite/?someparam=somevalue works for me – Mustafa – 2014-10-23T17:23:04.623

This is the most annoying thing about Chrome. Like bluescreen is for Windows. – Jo Smo – 2016-10-17T06:58:52.960

1@JDIsaacks you could use a Chrome exclusively to debugging (i.e. Chrome Canary) – athosbr99 – 2017-06-10T19:39:05.277

Does this still happen when you restart? It should stop after you restart with a fresh session – random – 2011-06-30T17:12:52.527

1@random, restarting chrome does seem to fix it. However, I usually have a lot of windows open (ie: docs, db connections, tutorials, the page I am working on, etc.) If I am troubleshooting something it can take several tries before figuring out whats going on. I wouldn't really consider it ideal to have to keep closing all my windows. Thanks. – JD Isaacks – 2011-06-30T17:22:15.910

2Workaround: Use 302 (temporary) redirects while testing, and switch to 301 (permanent) when you're done. (Caveat: Some browsers (Firefox) will cache even 302 redirects when they're going from http to https versions of the same page.) – TRiG – 2013-10-07T16:28:08.797

Answers

334

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.

random

Posted 2011-06-30T17:05:28.303

Reputation: 13 363

3Latest version of chrome, this option would be "Cached images and files" instead of "Empty the cache" – Dan R – 2014-08-07T15:38:48.470

23I keep getting redirected, even in incognito mode. – Gaia – 2014-09-21T16:49:40.767

2@Gaia yea, that seems to be problem in Chrome incognito. If you are just testing, you might want to use Firefox for this. Firefox private browsing works fine :) – chhantyal – 2015-01-26T14:19:48.143

Surprised this didnt pop up before here, see http://superuser.com/a/869739/68374

– Gaia – 2015-01-26T18:12:52.703

11

Note that HTTP 301 is Moved Permanently so caching the response is perfectly allowed. If you don't want the response to be cached, try 302 or 307. https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#3xx_Redirection

– a CVn – 2015-03-19T14:01:07.800

Refer to this answer if you wish to clear only the cache for a specific redirect, and not your entire cache: http://superuser.com/a/869739/68374

– Gaia – 2015-03-20T13:59:29.500

8The keyboard shortcut for this is Ctrl + Shift + Delete. – 0xcaff – 2015-12-26T22:37:18.453

1It did not work for me with only Cached images and files selected. I also needed Delete cookies and other site and plug-in data. What also did not work was: Disable cache in dev tools, delete cookies from this page, hard reload. – PiTheNumber – 2016-08-02T09:40:58.793

I just tested it and it worked fine using only Cached images and files. I did NOT need to delete cookies or other size data. @PiTheNumber maybe make sure you've set the time far back enough? – Django Reinhardt – 2016-08-02T12:04:07.843

@DjangoReinhardt I started with the lowest time span and only Cached images and files and continuesly increased options and time span. Cached images and files and full time span did not work in my case. – PiTheNumber – 2016-08-02T16:07:51.643

On Chrome 54.x Delete cookies and other site and plug-in data and Cached images and files worked for me – 2upmedia – 2016-11-10T01:16:38.200

Note that in the settings you are asked how far back you should delete cached files. By default it says over the past hour, but you may need to go further back depending on when the 301 Moved Permanently was first received by your browser. – AjaxLeung – 2017-08-07T06:04:00.093

Incognito seems to work for me, even when the original (then changed) redirect was cached 3 days earlier. – Juha Untinen – 2017-08-28T16:04:57.053

1Emptying the entire cache is a bit radical as you would need to log-in on many sites again. Just empty Cached images and files which worked fine for me on Chrome. – Alex – 2017-10-13T08:41:21.987

1This worked a treat - was ready to throw the computer out the window! – HappyCoder – 2018-04-25T15:43:54.477

This + a browser restart did the trick for me. – Mahn – 2019-03-28T12:19:08.727

1If you use incognito mode, it is unnecessary to close the browser. Simply close all incognito tabs. – MetaEd – 2014-02-03T00:21:44.843

160

This is the sure proof way to clear Chrome's sticky memory for redirects 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

Posted 2011-06-30T17:05:28.303

Reputation: 4 549

1As an aside: this is not available on a Mac. – Arjan – 2015-08-04T10:15:59.263

7this does not always delete cached redirects – Claudiu Creanga – 2015-09-10T13:48:10.613

@Claudiu what kind of redirect it doesn't delete? You tried the 3rd option, correct? – Gaia – 2015-09-10T21:22:08.770

9It is available on Mac, but the menu is only available if you have the dev tools open. I assume this might be the same on Windows. – Percy – 2015-10-28T13:48:10.167

5Mac OS X, Yosemite. Fighting with an http to https permanent redirect, only this option worked. All the others, including the "Disable cache (while DevTools is open)", made no difference. – Carles Sala – 2017-02-11T14:29:56.533

1works like a charm on macOS (High Sierra), Chrome 62. (Though I had to right click instead of left click and hold.) – Leo Lei – 2017-11-30T10:00:32.503

1Also, in my case it was a permanent redirect, instead of a temporary one. I suspect that is why the other solutions didn't work for me. – Leo Lei – 2017-11-30T10:02:09.730

1It's kind of hard to hold the refresh button on a page that already redirects you... – Roger Collins – 2018-03-20T23:46:15.743

@RogerCollins you can use the above from the page you are being redirected TO. – Gaia – 2018-03-21T01:08:00.427

1How cool is that. It's interesting that you have to be in developer mode. Nothing else was working, but that did, thanks. – Jeremy Holovacs – 2018-03-25T19:31:41.510

That's not going to work when you have to type the URL in! Reload will reload the current page, not what you enter into the address bar! If it is redirecting, you will be on the final page when you try to reload, not the starting page you are trying to reach! This is a nonsense answer. – Chloe – 2018-11-15T02:29:58.647

If you end up on an FQDN that is on a different domain from where the redirect occurred, that would be the case. Most of the time it isn't the case, but when it is, you need to catch it with an ESC or stop before the redirect occurs. You can also use the developer tools to not follow a redirect. Clearly not a nonsensical answer if it worked for so many people. – Gaia – 2018-11-15T20:39:59.247

1As on June 2019, this is the only approach that worked for me. Thanks :) – Rohit Jain – 2019-06-19T08:52:22.767

115

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

Posted 2011-06-30T17:05:28.303

Reputation: 1 251

2This didn't work for me. Even using a different port (:8080) it changed to https which seems like a Chrome bug. – jwadsack – 2017-02-21T19:02:12.267

I'm already doing the same thing, but it does not work always, sometimes I need to press ctrl+shift+r (ctrl+f5) to get the newer version of the web page, or partial pages included inside the page – Mohammad Kermani – 2017-04-30T12:34:17.830

If there is a wildcard cached 301 this may not work since its "remembering" to forward everything after the TLD. – dhaupin – 2017-05-22T17:16:39.850

10Yep, this works. example.com becomes example.com?. I'ts the easiest of the bunch – fregante – 2014-01-24T22:40:21.657

2This is an awesome trick. I assume you can use this indefinitely ?abc, ?abc2 etc... – brentonstrine – 2014-05-12T20:36:20.127

92

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

Posted 2011-06-30T17:05:28.303

Reputation: 4 987

What does "delete the last hour." means? How to do it? – Mikaël Mayer – 2015-06-10T21:03:39.527

1@MikaëlMayer When you click "History > Clear browsing data", you can select a timeframe to remove data ("the past hour", "past week" etc) – dbr – 2015-06-26T13:16:53.810

No..! Clearing browsing data for a site will not remove the 301 redirect behavior. Not in Chromium 64.0.x anyway – patricktokeeffe – 2018-02-04T04:26:51.597

Clearing "1 hour" makes you logout from all Google products and accounts. What a good advice... – Luciano Fantuzzi – 2018-02-25T19:21:50.913

ockquote>

You don't have to lose your entire cache. Just follow the redirect and delete the last hour.

That's still worse than "delete the last redirect" which is the feature they wontfixed. – rox0r – 2018-02-27T17:53:51.813

@LucianoFantuzzi just browsing data and/or cache, but definitely not cookies! (still a hassle though) – barlop – 2018-07-06T10:40:35.673

Time to develop on a different browser then. – marek.m – 2019-10-01T09:06:11.310

67

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.

Mike Gossmann

Posted 2011-06-30T17:05:28.303

Reputation: 791

9note: if devTools is open, there is a fast way to delete cache: click on refresh button with right click and choose full reload ;) – user65130 – 2014-11-21T17:08:29.573

5this does not work all the time. I deleted all my cache and still redirecting. Only with incognito mode it works and you get consistent behaviour – Claudiu Creanga – 2015-09-10T13:47:43.700

2Why is this not the top solution? the others are awful by comparison! – Brian – 2016-01-31T01:26:16.800

4Does not work any more... Probably worked in 2014 – Lord Loh. – 2016-09-01T17:24:42.157

@LordLoh. I've just tried this on the latest version of Chrome, and it worked exactly as expected. With the devtools closed, the redirect is cached. Reloading the page with the tools open does not redirect. – Mike Gossmann – 2016-09-01T18:58:00.417

Sad. Does not work for me. I can curl the url and see a 404 header (as it should), but chrome redirects me. I do not even the see the redirect in the network tab in the developer tools. Firefox is not behaving the same way as chrome. h-ttps://www.lohray.com/ > 404, h-ttp://www.lohray.com > h-ttps://lohray.com and h-ttp://lohray.com > h-ttps://lohray.com. However, typing the h-ttps://www.lohray.com triggers chrome to fetch h-ttps://lohray.com/ (the hyphen is to format the comment) – Lord Loh. – 2016-09-02T04:41:18.257

What I did to make this work is to view a random page that you know exists. Alternatively, if you have a local version you can change your hosts file to point to that, change it back to the actual domain, and then do the reload/reset – Shane on a bike – 2016-09-15T16:10:35.213

This worked perfectly for me in 2018, latest version of Chrome. – MSpreij – 2018-11-13T20:13:46.543

23

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

Posted 2011-06-30T17:05:28.303

Reputation: 379

2You'll find the option "disable cache" on the network tab too, it is the same option. For debugging redirects I would suggest using the "preserve log", too. – Trendfischer – 2015-10-06T12:07:18.380

15

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.

McGuireV10

Posted 2011-06-30T17:05:28.303

Reputation: 271

1Works on Chrome 56 – spencer.sm – 2017-02-09T00:13:21.207

Still works on Chrome 67 – SCO – 2018-09-19T08:15:41.100

1Don't work on Chrome 71. The net-internals events viewer and related functionality has been removed. – userlond – 2018-12-16T07:42:42.743

8

.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/

Lucas Bustamante

Posted 2011-06-30T17:05:28.303

Reputation: 237

This was my culprit for sure! I spend HOURS trying to figure out what the hell was going on. Thanks for posting this! – Jabari – 2017-12-16T23:25:02.647

This answer needs more votes. It might not be the problem that the questioner had but it will be for many devs that find this answer in their search results. – bp. – 2018-01-25T07:41:33.800

God! Who would ever come up with such brilliant idea! – Pavel Niedoba – 2019-06-03T20:12:47.247

7

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.

Matthew Blackford

Posted 2011-06-30T17:05:28.303

Reputation: 179

2This only works for javascript and metatag redirects. HTTP redirects are still followed – fregante – 2014-11-26T15:46:57.217

4Didn't work for me in Chrome 25 – swrobel – 2013-03-20T23:52:22.440

3This doesn't work if the redirect is for all pages. I have a www. -> no www. redirect - so the redirect is on the first hit, so I can't refresh anything. Each time I try to go to the page to refresh it follows the 301 - then it's too late! – Ian Grainger – 2013-03-25T11:12:05.090

1@Ian What if you type in the address bar view-source:www.example.com ? Does that let you refresh without it being redirected? – Matthew Blackford – 2013-03-26T00:13:37.083

1@MatthewBlackford AFAICT the same thing, I actually get the source of the redirected page. Not sure my test was that great, though TBH. I've deleted browsing history to 'fix' this problem. – Ian Grainger – 2013-03-26T14:07:52.357

1This worked in Chrome 33. Nice one. – dav_i – 2014-03-31T21:16:54.697

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

Posted 2011-06-30T17:05:28.303

Reputation: 169

1Hey, thanks. This really helps with sudden https redirects cache. – Ruberoid – 2016-01-03T17:46:03.907

5

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

Posted 2011-06-30T17:05:28.303

Reputation: 71

This is the only answer that worked for me. – JaredThirsk – 2018-03-03T21:45:30.917

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.

Tom Wilson

Posted 2011-06-30T17:05:28.303

Reputation: 41

3

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

Posted 2011-06-30T17:05:28.303

Reputation: 131

The strange thing is that this option does not help. I disabled the cache but it still says in the network tab 301 Moved Permanently (from disk cache). – mgutt – 2017-10-25T13:34:37.987

That is same exact thing as clicking 'disable cache' while network tab is open. Nope - does not clear redirects. – bshea – 2018-08-01T15:13:44.980

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.

Ogier Schelvis

Posted 2011-06-30T17:05:28.303

Reputation: 151

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

kqw

Posted 2011-06-30T17:05:28.303

Reputation: 1 781

1

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

Ryu_hayabusa

Posted 2011-06-30T17:05:28.303

Reputation: 251

Why would you hold it instead of simply pressing Ctrl+R? – gronostaj – 2015-10-01T18:29:11.330

@gronostaj Wasn't my answer plain and simple ?? . Without holding, it would be just a normal refresh. Which does not clear cached resources or redirects. – Ryu_hayabusa – 2015-10-07T13:02:43.617

Holding is just like pressing it multiple times. Open Notepad and hold R, multiple Rs will appear. This is exactly the same, but with Ctrl. Holding Ctrl+R is an exact equivalent of pressing it dozen times per second for a few seconds. That's not smart, it's abusing built-in refresh mechanism and relying on undocumented behavior. – gronostaj – 2015-10-07T14:06:24.820

@gronostaj Yes it is an undocumented behavior. The accepted answer does not works for me. That's why i shared it here. I don't see any other way to clear cached redirect . If you know any other methods , feel free to share. – Ryu_hayabusa – 2015-10-10T18:44:55.193

Tried and did not work (301 redirect on whole domain). – mgutt – 2017-10-25T13:28:39.140

0

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.

Damodar Bashyal

Posted 2011-06-30T17:05:28.303

Reputation: 103

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

Posted 2011-06-30T17:05:28.303

Reputation: 147