如何从URL中删除锚标记?

Nat*_*her 3 apache url .htaccess mod-rewrite url-rewriting

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

http://rivo.wpengine.com/why-rivo/#toggle-id-3
Run Code Online (Sandbox Code Playgroud)

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

我可以对.htaccess文件做些什么,也许使用mod_rewrite?

Jon*_*Lin 6

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

例如,from:使用JavaScript删除URL中的片段w/out导致页面重新加载

// 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));
}
Run Code Online (Sandbox Code Playgroud)