如何从URL中删除锚点标签?

3
我正在尝试删除在折叠内容时使用的锚点标签,或者一个包含指向页面其他部分的锚点的链接。
http://rivo.wpengine.com/why-rivo/#toggle-id-3

我希望删除此网址中的#toggle-id-3部分。

我能否在.htaccess文件中进行一些操作,也许使用mod_rewrite?

1个回答

7

你不能使用htaccess或mod_rewrite来删除URL片段,因为它们(指URL片段)从未发送到服务器。就服务器而言,它们不存在。您需要使用JavaScript或其他客户端解决方案来删除它们。

例如,从:使用JavaScript删除URL中的片段而不会导致页面重新加载

// remove fragment as much as it can go without adding an entry in browser history:
window.location.replace("#");

// slice off the remaining '#' in HTML5:    
if (typeof window.history.replaceState == 'function') {
  history.replaceState({}, '', window.location.href.slice(0, -1));
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接