Skip to content

Instantly share code, notes, and snippets.

@magnetikonline
Last active May 18, 2018 17:23
Show Gist options
  • Save magnetikonline/34ba0706144c368d68f6 to your computer and use it in GitHub Desktop.
Save magnetikonline/34ba0706144c368d68f6 to your computer and use it in GitHub Desktop.
Ensure HTTP redirects are not cached by client browser.

Ensure HTTP redirects are not cached

Chrome (at least) likes to cache HTTP redirects, an issue if you are running logging/reporting on those redirect actions server side. Combat this with some HTTP headers.

Location: http://domain.com/redirect
Cache-Control: must-revalidate,no-cache,no-store
Expires: Sat, 01 Jan 2000 00:00:00 GMT

Or in PHP land that could be...

<?php
header('Location: http://domain.com/redirect',true,301);
header('Cache-Control: must-revalidate,no-cache,no-store');
header('Expires: Sat, 01 Jan 2000 00:00:00 GMT');

The magic for Google Chrome in particular is the use of no-store.

See more about that here: https://code.google.com/p/chromium/issues/detail?id=28035.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment