476

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?

7
  • Does this still happen when you restart? It should stop after you restart with a fresh session
    – random
    Jun 30, 2011 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, 2011 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 7, 2013 at 16:28
  • 1
    Entering a new www.mywebsite/?someparam=somevalue works for me
    – Mustafa
    Oct 23, 2014 at 17:23
  • 1
    @JDIsaacks you could use a Chrome exclusively to debugging (i.e. Chrome Canary)
    – athosbr99
    Jun 10, 2017 at 19:39

20 Answers 20

354

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.

17
  • 3
    Latest version of chrome, this option would be "Cached images and files" instead of "Empty the cache"
    – Dan R
    Aug 7, 2014 at 15:38
  • 30
    I keep getting redirected, even in incognito mode.
    – Gaia
    Sep 21, 2014 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, 2015 at 14:19
  • 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. en.wikipedia.org/wiki/List_of_HTTP_status_codes#3xx_Redirection
    – user
    Mar 19, 2015 at 14:01
  • 10
    The keyboard shortcut for this is Ctrl + Shift + Delete.
    – 0xcaff
    Dec 26, 2015 at 22:37
207

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)

14
  • 2
    As an aside: this is not available on a Mac.
    – Arjan
    Aug 4, 2015 at 10:15
  • 7
    this does not always delete cached redirects Sep 10, 2015 at 13:48
  • 14
    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, 2015 at 13:48
  • 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. Feb 11, 2017 at 14:29
  • 3
    As on June 2019, this is the only approach that worked for me. Thanks :)
    – Rohit Jain
    Jun 19, 2019 at 8:52
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.

5
  • 10
    Yep, this works. example.com becomes example.com?. I'ts the easiest of the bunch
    – fregante
    Jan 24, 2014 at 22:40
  • 3
    This is an awesome trick. I assume you can use this indefinitely ?abc, ?abc2 etc... May 12, 2014 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, 2017 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 Apr 30, 2017 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, 2017 at 17:16
94

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.
7
  • What does "delete the last hour." means? How to do it? Jun 10, 2015 at 21:03
  • 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
    Jun 26, 2015 at 13:16
  • No..! Clearing browsing data for a site will not remove the 301 redirect behavior. Not in Chromium 64.0.x anyway Feb 4, 2018 at 4:26
  • Clearing "1 hour" makes you logout from all Google products and accounts. What a good advice... Feb 25, 2018 at 19:21
  • > 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
    Feb 27, 2018 at 17:53
74

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.

8
  • 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, 2014 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 Sep 10, 2015 at 13:47
  • 2
    Why is this not the top solution? the others are awful by comparison!
    – Brian
    Jan 31, 2016 at 1:26
  • 4
    Does not work any more... Probably worked in 2014
    – Lord Loh.
    Sep 1, 2016 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. Sep 1, 2016 at 18:58
25

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.

1
  • 3
    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. Oct 6, 2015 at 12:07
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.

3
  • 1
    Works on Chrome 56
    – spencer.sm
    Feb 9, 2017 at 0:13
  • Still works on Chrome 67
    – SCO
    Sep 19, 2018 at 8:15
  • 3
    Don't work on Chrome 71. The net-internals events viewer and related functionality has been removed.
    – userlond
    Dec 16, 2018 at 7:42
9

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.

6
  • 4
    Didn't work for me in Chrome 25
    – swrobel
    Mar 20, 2013 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! Mar 25, 2013 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? Mar 26, 2013 at 0: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. Mar 26, 2013 at 14:07
  • 2
    This only works for javascript and metatag redirects. HTTP redirects are still followed
    – fregante
    Nov 26, 2014 at 15:46
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/

3
  • 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, 2017 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, 2018 at 7:41
  • God! Who would ever come up with such brilliant idea! Jun 3, 2019 at 20:12
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.

1
  • This is the only answer that worked for me. Mar 3, 2018 at 21:45
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

1
  • 1
    Hey, thanks. This really helps with sudden https redirects cache.
    – Ruberoid
    Jan 3, 2016 at 17:46
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.

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

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, 2017 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 1, 2018 at 15:13
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
  • 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 2, 2020 at 22:02
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

1

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

5
  • Why would you hold it instead of simply pressing Ctrl+R?
    – gronostaj
    Oct 1, 2015 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. Oct 7, 2015 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 7, 2015 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. Oct 10, 2015 at 18:44
  • Tried and did not work (301 redirect on whole domain).
    – mgutt
    Oct 25, 2017 at 13:28
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.

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

0

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.

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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.