chris_cm
chris_cm

Reputation: 167

How to force browsers not to cache destination of redirects

I am working on a PHP script that redirects to a random URL on my blog by adding a query like "?random" to the URL. The problem is that some browsers seem to cache the destination and so the "?random" parameter always redirects to the same page. For some browsers I managed to prevent the caching by redirecting with the code "307", but now I discovered that Firefox 57 still caches that link.

Is there any recommended redirection code for that purpose, or any other workaround? I am aware that I could just add a dummy parameter with a random token like "?random&token=..." but I want that visitors can use that link from their own websites where I obviously cannot add a random token.

Upvotes: 2

Views: 1408

Answers (1)

chris_cm
chris_cm

Reputation: 167

Based on @charlotte-dunois comment, now as complete answer to the question:

header( 'Cache-Control: no-cache, must-revalidate' );
header( 'Location: ' . $permalink, true, 307 );
exit;

Upvotes: 3

Related Questions