重定向是保持哈希 [英] redirect is keeping hash

查看:306
本文介绍了重定向是保持哈希的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于某种原因,当我重定向到头部(位置)时,新页面会保留哈希。

For some reason when I redirect with header("Location") the new page keeps the hash.

因此,如果您使用 example.com/index.html#signup

我使用

I redirect with

header("Location: /account.html");
exit;

但是它会显示 example.com/account.html#signup code>

But then it shows example.com/account.html#signup

为什么会发生这种情况,我该如何阻止它?即 example.com/account.html

Why is this happening and how can I stop it? ie example.com/account.html

注意:

我使用.htaccess将 file.html 重定向到 file.php code>

I am using an .htaccess to redirect file.html to file.php

RewriteRule ^([a-zA-Z0-9-_.]+)\.html$ $1.php [L]


推荐答案

我该如何阻止它是在 Location 标题中指定一个空的散列:

The simple answer to "how do I stop it" is to specify an empty hash in the Location header:

header('Location: /account.html#');

然而,这种行为并不能保证全面。它似乎可以在我的快速测试中用于WebKit和IE9。尽管如此,您还是偶然发现了 HTTP规范中的黑洞

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.

这篇关于重定向是保持哈希的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆