出于某种原因,当我使用 header("Location")
重定向时,新页面会保留哈希值。
所以如果你在 example.com/index.html#signup
我重定向
header("Location: /account.html");
exit;
但随后显示 example.com/account.html#signup
为什么会发生这种情况,我该如何阻止它?即 example.com/account.html
注意:
我正在使用 .htaccess 将 file.html
重定向到 file.php
RewriteRule ^([a-zA-Z0-9-_.]+)\.html$ $1.php [L]
最佳答案
“我如何停止它”的简单答案是在 Location
header 中指定一个空散列:
header('Location: /account.html#');
但是,这种行为并不能保证全面。在我的快速测试中,它似乎适用于 WebKit 和 IE9。尽管如此,您还是偶然发现了一个 black hole in the HTTP specification .
关于php - 重定向是保持散列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12432212/