Apache - how to disable browser caching while debugging htaccess

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.


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

CTRL-SHIFT-N

Very useful for debugging.


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


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.