是否可以在 http-redirect(302 或 307)时设置一些 http 标头?
<?
header("some-header: xxx");
header("Location: http://other.domain.com/foo.php",TRUE,307);
?>
是否可以在 http-redirect(302 或 307)时设置一些 http 标头?
<?
header("some-header: xxx");
header("Location: http://other.domain.com/foo.php",TRUE,307);
?>
您基本上可以将所需的任何 http 标头设置为服务器或客户端。
如果您指示重定向,则应按照示例建议提供 Location 标头。您还应该确保您的响应标头引用该响应,而不是客户端被重定向到的资源。即您的标头可以包括 Content-Length: 0,省略 Content-Type 标头等。
不确定这是否是您所追求的 - 这个问题可以更详细地说明。
您始终可以执行重定向 301/307。有办法做到这一点1)通过java代码做到这一点:
response.setStatus(307);
response.setHeader("Location",url);
2)同样的事情可以在 JSP 中完成。
这里的提示是:始终使用 setHeader 函数而不是 addHeader 函数,因为它们的行为方式不同。