# Mod Rewrite - Regex for Hiding #'s From Same-Page Link URLs

**URL:** <https://forum.kirupa.com/t/mod-rewrite-regex-for-hiding-s-from-same-page-link-urls/265644>\
**Category:** programming\
**Created:** [July 11, 2008, 12:07am UTC](https://forum.kirupa.com/t/mod-rewrite-regex-for-hiding-s-from-same-page-link-urls/265644 "2008-07-11T00:07:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nickcherryjiggz](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/nickcherryjiggz/32/2107_2.png) [@nickcherryjiggz](https://forum.kirupa.com/u/nickcherryjiggz)\
**Post date:** [July 11, 2008, 12:07am UTC](https://forum.kirupa.com/t/mod-rewrite-regex-for-hiding-s-from-same-page-link-urls/265644/1 "2008-07-11T00:07:50Z")

</div>

The title pretty much covers it. Could someone help me out with the regex for hiding the pound sign (#) and everything after it when the user clicks a link to an anchor on the same page? Thanks for any help!

---

<div class="post-metadata">

**Author:** ![jwilliam](https://avatars.discourse-cdn.com/v4/letter/j/cc9497/32.png) [@jwilliam](https://forum.kirupa.com/u/jwilliam)\
**Post date:** [July 11, 2008, 1:29am UTC](https://forum.kirupa.com/t/mod-rewrite-regex-for-hiding-s-from-same-page-link-urls/265644/2 "2008-07-11T01:29:38Z")

</div>

Well, you’ll need to use javascript to achieve this because clicking a link with a hash (#) in it does not send a request to the web server. You’d have to place an “onclick” event handler on each of your anchors to call the following function:

```auto

function removeHash(e)
{

  if(e == null) {
    e = window.event;
  }

  var target = (e.target == null) ? e.srcElement : e.target;

  var new_url = target.href.replace(/#.*/, '');

}

```

new\_url will contain your url with the hash and everything after it removed.

Hope this helps…
