26

I'm trying to debug an .htaccess file. FireFox keeps caching redirects and I can't get around them. Normally I would hit Ctrl + F5, but because it has already redirected me to another page, that just refreshes the page I was sent to and not the url I typed in. Is there a way to force a refresh of a url?

Here's an example:

  • Redirect example.com/hi to example.com/hello, test in FireFox and it works
  • Remove this line from .htaccess
  • Type example.com/hi in FireFox, it still redirects to example.com/hello
  • Type example.com/hi in Chrome, it does not redirect

This is why I think it's a browser caching issue, not server caching.

Edit: This seems to be FireFox specific, a quick solution is to use Chrome instead. The cache expired after an hour, which is way too long when trying to debug.

Andrew
  • 18,680
  • 13
  • 103
  • 118
hamboy
  • 727
  • 2
  • 8
  • 21
  • One of the most annoying problems when developing. Still valid in the latest Chrome. And this is more than ten years later. – Avatar Dec 25 '22 at 14:53

12 Answers12

17

If you're using RewriteRule, just use R instead of R=301. For other purposes, you'll have to clear your browser cache whenever you change a redirect. (If you don't know how to clear your browser cache, googling for a how-to should provide a quick and easy answer - or feel free to comment and I'll help you out.)

Simply put, try to avoid 301s wherever possible until you've got your redirects working normally. If you can't avoid them, get ready to clear your browser cache regularly.

Dan Ambrisco
  • 865
  • 7
  • 13
  • 1
    I don't think this really answers the question, I'm having the same issue with Firefox where it seems to cache the htaccess file but no matter how many times I clear the cache it will not refresh with my latest version. The solution at the moment is to use Chrome. – Tim at MastersAllen Aug 09 '12 at 10:45
  • 2
    Browsers don't cache .htaccess files (since they never see them), but they do cache redirects. There's absolutely no reason proper 302 redirects shouldn't work as expected, unless this actually is a Firefox bug (in which case you should file a ticket with them). – Dan Ambrisco Oct 02 '12 at 05:17
  • Temporarily changing it into 302 when you actually need a 301 might be forgotten when you're done testing. Further, it is just perfectly possible to clear the browsers cache. – Lode May 22 '15 at 08:36
  • 7
    "google it" isn't an answer :[ I googled it and im here. – Andrew Mar 06 '16 at 18:21
  • 2
    Figured it out for Chrome, see my answer below. – Andrew Mar 06 '16 at 18:29
  • What if I have created flawed redirects on a live website, meaning these redirects are now cached for many visitors. I cannot clear my visitors browser cache as I dont have access, and I would rather not ask visitors to clear their cache, as this looks unprofessional and they are unlikely to follow such directions anyway. – Levi Apr 09 '17 at 18:02
  • Good advice, so intuitive when someone else tells you the answer. Thank you. – Clinton Oct 30 '20 at 22:41
10

Clearing the Firefox' network cache works for me. Also for 301 redirects.

Preferences/Options > Advanced > Network > Cached web content.

Clear network cache in Firefox preferences

See https://support.mozilla.org/en-US/kb/how-clear-firefox-cache

Lode
  • 2,160
  • 1
  • 20
  • 25
  • This worked for me too. We made a mistake with the .htaccess file and got a 301 in a loop. Chrome saw the change immediately, but FF didn't. To say it doesn't cache the .htaccess file is correct, but FF seems to get it's knickers in a twist. – Nick Green Jun 04 '16 at 09:19
7

In Google Chrome, open a new tab in "Incognito" mode using:

CTRL-SHIFT-N

Very useful for debugging.

DrBeco
  • 11,237
  • 9
  • 59
  • 76
  • But what if you want to use the non-incognito mode. How to "clear" the htaccess redirect then? – Avatar Dec 25 '22 at 14:53
7

I think it's worth weighing in here just in case my experience helps anyone. I regularly switch back and forth between a development and production branch on my local machine. The development branch is my local environment and the production branch is for my remote server. The only difference between the two environments is the .htaccess file. My remote server needs a rewrite rule in case someone does not enter "www" before the URL:

# If www is missing from the beginning of the URL
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

However, this rewrite rule does not work for my local environment because of the URL structure. So in my local version of .htaccess I comment out the rewrite rules.

What I've noticed is that Chrome does not seem to go to my local server to get the latest .htaccess file every time. It's obviously caching the rewrite because when I switch from my production branch to my development branch I get something that looks like this:

www.www-local.myurl.local

If I use Safari, I get the correct URL:

www-local.myurl.local

To resolve this Chrome issue, I went to the Developer Tools > Settings > General > and check "Disable cache (while DevTools is open)"

With this checked, I just need to open Dev Tools and reload to get the current .htaccess.

Vaughn D. Taylor
  • 617
  • 1
  • 8
  • 20
6

To force clear htaccess/redirect caches in Google Chrome:

  1. Go to Settings > Advanced > Privacy > Clear Browsing Data
  2. Select "Cached Images and Files"
  3. Click Clear Browsing Data

Your page should now load the fresh htaccess settings.

Andrew
  • 18,680
  • 13
  • 103
  • 118
4

In Firefox open Developer Toolbar by pressing Option Command I. Then click Settings (It's a little cog icon) and under Advanced Settings put a tick next to Disable HTTP Cache (when toolbox is open). This did the trick for me.

Gdev
  • 167
  • 1
  • 11
3

In Chrome, you can disable browser cache in the Developer Tools panel

Command+Option+C (Mac) or Control+Shift+C (Windows, Linux, Chrome OS).

In the Network tab, you can find Disable cache checkbox.
It only works while the Developer Tools panel is open. enter image description here

Amir Khorsandi
  • 3,542
  • 1
  • 34
  • 38
0

After trying to refresh my cache countless times I decided to clear the cookies for my site, I don't know why or how but that cleared it for me. Maybe it's something specific to Magento but it might be more general.

0

In Google Chrome open Developer Toolbar. Then click Settings (It's a 3 dots icon) and under Network section, check on "Disable cache (while DevTools is open)".

Cong Nguyen
  • 3,199
  • 1
  • 23
  • 22
0

For chrome, you can do this per-page without clearing out all browser cache; just open the develop tools (You can use shortcut ctrl + shift + I). Once it comes open, right click on the reload icon and click "Empty cache and hard reload". enter image description here

0

I finally found a solution for Chrome:

disable cache

In the Web Developer, open Tab "Network" and enable "Disable cache".

This worked for me.

Avatar
  • 14,622
  • 9
  • 119
  • 198
-1

Well, you can simply clear your htaccess cache using Firefox addon Clear Cache. Better than any CTRL + R

https://addons.mozilla.org/en-US/firefox/addon/clear-cache-button/

FG-Techs
  • 7
  • 1