前言:
我在以下地址:
http://www.example.com/#contact
成功提交联系表单后,用户将被重定向到以下地址:
http://www.example.com/thanks
借助以下代码:
// Redirect to thank you page
redirect_to("thanks");
函数redirect_to()定义为:
// Page redirection
function redirect_to($url)
{
if(isset($url) && $url != '')
{
header("Location: " . $url);
exit();
}
}
感谢页面的htaccess规则是:
# Thanks Page
RewriteRule ^thanks/?$ thanks.php [QSA,L]
#RewriteRule ^thanks/$ thanks.php [QSA,L]
问题:
问题是哈希 (#) 字符,即片段部分仍然与 URL 保持一致,例如:
http://www.example.com/thanks#contact
该部分如何#contact
如果我将页面重定向到thanks
,请坚持使用主URL ?
我们如何通过 htaccess 或 PHP 甚至通过 JS 排除/删除它?
最佳答案
这个问题之前就被问过。
标记为答案的响应是:
block 引用>The simple answer to "how do I stop it" is to specify an empty hash in the Location header:
header('Location: /account.html#');
However, this behavior isn't guaranteed across the board. It seems to work in WebKit and IE9 in my quick test. Nevertheless, you've stumbled on a black hole in the HTTP specification.
关于javascript - 如何在 PHP 中将页面重定向到不带井号 (#) 的 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45994017/