由于浏览器缓存,PHP标头301重定向不起作用

问题描述:

我的代码如下:

<?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.

我知道它必须与缓存相关,但这是绕过上述重定向的缓存的最有效,最标准化的方法?我会使用php还是javascript?

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?

谢谢。

试试这个:

header('Cache-Control: no-cache');
header('Pragma: no-cache');

浏览器可能会忽略您的请求,但这应该可以解决问题。

The browser may ignore your request, but this should do the trick.