【问题标题】:How do you remove anchor tags from URL?如何从 URL 中删除锚标记?
【发布时间】:2013-12-10 12:18:56
【问题描述】:

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

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

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

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

【问题讨论】:

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


    【解决方案1】:

    您不能使用 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));
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-06-30
      • 1970-01-01
      • 2019-03-13
      • 2011-10-08
      • 2013-12-05
      • 1970-01-01
      • 2021-05-24
      • 2016-06-27
      相关资源
      最近更新 更多