如何从URL中删除锚标记?

时间:2013-11-25 16:55:59

标签: apache .htaccess url mod-rewrite url-rewriting

我正在尝试删除在切换手风琴时使用的锚标签或包含锚到页面另一部分的链接。

http://rivo.wpengine.com/why-rivo/#toggle-id-3

我想删除此网址的#toggle-id-3部分。

我可以使用.htaccess文件执行某些操作,也许使用mod_rewrite?

1 个答案:

答案 0 :(得分:6)

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

例如,来自:Remove fragment in URL with JavaScript w/out causing page reload

// 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));
}
相关问题