484

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,354
  • 11
  • 40
  • 41
  • Does this still happen when you restart? It should stop after you restart with a fresh session – random Jun 30 '11 at 17:12
  • 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 Jun 30 '11 at 17:22
  • 2
    Workaround: 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 Oct 07 '13 at 16:28
  • 1
    Entering a new `www.mywebsite/?someparam=somevalue` works for me – Mustafa Oct 23 '14 at 17:23
  • Please tell chrome we need a way out of this 301 hell hole: https://bugs.chromium.org/p/chromium/issues/detail?id=633023&can=1&q=clear%20301%20redirects&colspec=ID%20Pri%20M%20Stars%20ReleaseBlock%20Component%20Status%20Owner%20Summary%20OS%20Modified – B T Aug 01 '16 at 02:14
  • This is the most annoying thing about Chrome. Like bluescreen is for Windows. – Jo Smo Oct 17 '16 at 06:58
  • 1
    @JDIsaacks you could use a Chrome exclusively to debugging (i.e. Chrome Canary) – athosbr99 Jun 10 '17 at 19:39

20 Answers20

360

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,061
  • 4
  • 38
  • 56
random
  • 14,638
  • 9
  • 54
  • 58
  • 1
    If you use incognito mode, it is unnecessary to close the browser. Simply close all incognito tabs. – MetaEd Feb 03 '14 at 00:21
  • 3
    Latest version of chrome, this option would be "Cached images and files" instead of "Empty the cache" – Dan R Aug 07 '14 at 15:38
  • 31
    I keep getting redirected, even in incognito mode. – Gaia Sep 21 '14 at 16:49
  • 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 Jan 26 '15 at 14:19
  • Surprised this didnt pop up before here, see http://superuser.com/a/869739/68374 – Gaia Jan 26 '15 at 18:12
  • 11
    Note that HTTP 301 is **[Moved Permanently](https://en.wikipedia.org/wiki/HTTP_301)** 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 – user Mar 19 '15 at 14:01
  • 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 Mar 20 '15 at 13:59
  • 13
    The keyboard shortcut for this is `Ctrl` + `Shift` + `Delete`. – 0xcaff Dec 26 '15 at 22:37
  • 1
    It 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 Aug 02 '16 at 09:40
  • 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 Aug 02 '16 at 12:04
  • @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 Aug 02 '16 at 16:07
  • On Chrome 54.x `Delete cookies and other site and plug-in data` and `Cached images and files` worked for me – 2upmedia Nov 10 '16 at 01:16
  • 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 Aug 07 '17 at 06:04
  • Incognito seems to work for me, even when the original (then changed) redirect was cached 3 days earlier. – Juha Untinen Aug 28 '17 at 16:04
  • 1
    Emptying 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 Oct 13 '17 at 08:41
  • 1
    This worked a treat - was ready to throw the computer out the window! – HappyCoder Apr 25 '18 at 15:43
  • This + a browser restart did the trick for me. – Mahn Mar 28 '19 at 12:19
216

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
  • 6,699
  • 7
  • 34
  • 39
  • 2
    As an aside: this is not available on a Mac. – Arjan Aug 04 '15 at 10:15
  • 8
    this does not always delete cached redirects – Claudiu Creanga Sep 10 '15 at 13:48
  • @Claudiu what kind of redirect it doesn't delete? You tried the 3rd option, correct? – Gaia Sep 10 '15 at 21:22
  • 15
    It 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 Oct 28 '15 at 13:48
  • 2
    @Arjan it is available on a Mac see http://superuser.com/questions/304589/how-can-i-make-chrome-stop-caching-redirects/869739?noredirect=1#comment1369915_869739 – Gaia Oct 28 '15 at 19:24
  • 5
    Mac 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 Feb 11 '17 at 14:29
  • 1
    works like a charm on macOS (High Sierra), Chrome 62. (Though I had to right click instead of left click and hold.) – Leo Lei Nov 30 '17 at 10:00
  • 1
    Also, 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 Nov 30 '17 at 10:02
  • 2
    It's kind of hard to hold the refresh button on a page that already redirects you... – Roger Collins Mar 20 '18 at 23:46
  • @RogerCollins you can use the above from the page you are being redirected TO. – Gaia Mar 21 '18 at 01:08
  • 1
    How cool is that. It's interesting that you have to be in developer mode. Nothing else was working, but that did, thanks. – Jeremy Holovacs Mar 25 '18 at 19:31
  • 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 Nov 15 '18 at 02:29
  • 1
    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 Nov 15 '18 at 20:39
  • 3
    As on June 2019, this is the only approach that worked for me. Thanks :) – Rohit Jain Jun 19 '19 at 08:52
  • 1
    Wow -- who knew? This is brilliant. Every dev needs this. Thanks! – david.pfx Apr 25 '23 at 14:07
  • Is there a way that this helps when you can't get the browser to land on a site in the first place because it's already rerouting you? – Altimus Prime Jun 25 '23 at 23:30
128

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,381
  • 1
  • 8
  • 2
  • 10
    Yep, this works. `example.com` becomes `example.com?`. I'ts the easiest of the bunch – fregante Jan 24 '14 at 22:40
  • 3
    This is an awesome trick. I assume you can use this indefinitely `?abc`, `?abc2` etc... – brentonstrine May 12 '14 at 20:36
  • 2
    This didn't work for me. Even using a different port (:8080) it changed to https which seems like a Chrome bug. – jwadsack Feb 21 '17 at 19:02
  • 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 Apr 30 '17 at 12:34
  • If there is a wildcard cached 301 this may not work since its "remembering" to forward everything after the TLD. – dhaupin May 22 '17 at 17:16
95

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,107
  • 5
  • 27
  • 37
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.

Mike Gossmann
  • 881
  • 6
  • 4
  • 9
    note: if devTools is open, there is a fast way to delete cache: click on refresh button with right click and choose full reload `;)` – user65130 Nov 21 '14 at 17:08
  • 6
    this 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 Sep 10 '15 at 13:47
  • 2
    Why is this not the top solution? the others are awful by comparison! – Brian Jan 31 '16 at 01:26
  • 4
    Does not work any more... Probably worked in 2014 – Lord Loh. Sep 01 '16 at 17:24
  • @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 Sep 01 '16 at 18:58
  • 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. Sep 02 '16 at 04:41
  • 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 Sep 15 '16 at 16:10
  • This worked perfectly for me in 2018, latest version of Chrome. – MSpreij Nov 13 '18 at 20:13
  • This doesn’t work for cached http→https redirects – bfontaine Sep 18 '22 at 19:37
  • The last time I checked it works, as long as you try and navigate to the http version directly, and the redirect is just cached. If the URL used https pinning, then you need to unpin it first, so that the browser actually tries the non-http url. – Mike Gossmann Sep 22 '22 at 20:33
26

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
  • 409
  • 1
  • 6
  • 12
  • 4
    You'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 Oct 06 '15 at 12:07
  • [This article](https://www.ryadel.com/en/clear-google-chrome-redirect-cache-for-single-url-page-howto/#:~:text=%232%3A%20Clear%20Cache%20Data%20for%20a%20specific%20URL) describes how to do it from the network tab for a specific URL. I found thatv article first and only later this answer. – kriegaex Jul 09 '23 at 06:31
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.

McGuireV10
  • 331
  • 4
  • 10
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.

  • 4
    Didn't work for me in Chrome 25 – swrobel Mar 20 '13 at 23:52
  • 3
    This 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 Mar 25 '13 at 11:12
  • 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 Mar 26 '13 at 00:13
  • 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 Mar 26 '13 at 14:07
  • 1
    This worked in Chrome 33. Nice one. – dav_i Mar 31 '14 at 21:16
  • 2
    This only works for javascript and metatag redirects. HTTP redirects are still followed – fregante Nov 26 '14 at 15:46
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/

Lucas Bustamante
  • 534
  • 3
  • 13
  • This was my culprit for sure! I spend HOURS trying to figure out what the hell was going on. Thanks for posting this! – Jabari Dec 16 '17 at 23:25
  • 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. Jan 25 '18 at 07:41
  • God! Who would ever come up with such brilliant idea! – Pavel Niedoba Jun 03 '19 at 20:12
  • This answer doesn’t need any vote; it should be a comment. – bfontaine Sep 18 '22 at 19:39
  • @bfontaine when this answer was written back in 2017, a LOT of people used .dev as their local development domains. It was the default TLD for some popular localhost tools, such as Laravel Homestead, etc – Lucas Bustamante Sep 19 '22 at 01:58
  • I can understand that, but it’s not what OP asked for. – bfontaine Sep 19 '22 at 08:54
  • @bfontaine The HSTS preloaded header in Chrome causes a redirect from HTTP to HTTPS protocol, and it cannot be bypassed, so I think it's one of the many valid answers to a "chrome redirect" question. – Lucas Bustamante Sep 20 '22 at 13:41
6

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
  • 81
  • 1
  • 3
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
  • 1
  • 2
4

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
  • 141
  • 2
  • 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 Oct 25 '17 at 13:34
  • That is same exact thing as clicking 'disable cache' while network tab is open. Nope - does not clear redirects. – B. Shea Aug 01 '18 at 15:13
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
  • 41
  • 1
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.

  • This is the key answer because Windows uses Resolver Cache and no amount of clearing the browser or even uninstalling and reloading the browser will resolve the problem of a 301 redirect or a wrong address is stored in the Windows Resolver Cache. Well done on this answer, I hope people read it first otherwise they will waste a lot of time trying to find the answer. – Clinton Nov 02 '20 at 22:02
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,751
  • 1
  • 26
  • 35
1

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

Ryu_hayabusa
  • 271
  • 3
  • 4
  • Why would you hold it instead of simply pressing `Ctrl+R`? – gronostaj Oct 01 '15 at 18:29
  • @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 Oct 07 '15 at 13:02
  • 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 Oct 07 '15 at 14:06
  • @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 Oct 10 '15 at 18:44
  • Tried and did not work (301 redirect on whole domain). – mgutt Oct 25 '17 at 13:28
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

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!