How do you remove anchor tags from URL?

.htaccess, apache, mod-rewrite, url, url-rewriting

Solution

You can't use htaccess or mod_rewrite to remove URL fragments because they are never sent to the server. As far as the server is concerned, they don't exist. You'll need to use javascript or some other client side solution to remove them.

For example, from: 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));
}

Problem

I am trying to remove the anchor tags used when toggling the accordions or a link that includes an anchor to another part of the page. ``` http://rivo.wpengine.com/why-rivo/#toggle-id-3 ``` I would like to removing the `#toggle-id-3` part of this URL. Can I do something with the `.htaccess` file, maybe using mod_rewrite?

Original source

Related problems