问题
My code is the following:
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://newsite.com/");
?>
The issue I am having is several users have already reported the page not redirecting them and instead showing them the content on the old page, but later in the day it showed the correct redirect.
I know it has to be related to the caching but which is the most efficient and standardized way to bypass the cache for the above redirect? Would I use php or javascript?
Thank you.
回答1:
Try this:
header('Cache-Control: no-cache');
header('Pragma: no-cache');
The browser may ignore your request, but this should do the trick.
回答2:
The correct answer is what lucasvscn said with adding exit();
after the header tags. Cache control mention above actually caused an error for me.
来源:https://stackoverflow.com/questions/19983660/php-header-301-redirect-not-working-due-to-browser-cache