Q:

Remove hash and load URL minus hash

enter code hereThis JavaScript snippet removes the /#/and/everything/after from URL, and reloads the page. 
var loc = window.location.href,
    index = loc.indexOf('#');

if (index > 0) {
  window.location = loc.substring(0, index);
}

As a result, something like this:
http://www.somesite.com/#/somepage

reloads as this:
http://www.somesite.com

How can I modify the snippet, to make it remove only this part: #/, but keeo everything that comes after it, and load the page at the url that has everything before and after #/, like this:
http://www.somesite.com/somepage

A:

You could do
window.location = window.location.href.replace(/\/#\//, '/');

If you only want to reload when there's a #, you can do
if (window.location.href.indexOf('/#/')>=0) {
    window.location = window.location.href.replace(/\/#\//, '/');
}

EDIT : to add a # before the last token, you may do this :
var href2 = href.replace(/([^\/]+\/?)$/, '#/$1')

Examples :
"http://www.somesite.com/somepage?a=b" -> "http://www.somesite.com/#/somepage?a=b"
"http://www.somesite.com/somepage/" -> "http://www.somesite.com/#/somepage/"

