2

I have a website that generates the following URL on the home page in the browser bar:

http://example.com/int/bdf/eng/

I want change it to the following without reloading the page:

http://example.com

Is there an IE8+ solution available?

i know about window.history.pushState("", "", ""); but how to use it? Or would it be better to use a htaccess file?

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Jim
  • 923
  • 4
  • 17
  • 30
  • When you say change it, do you mean change it live on the page, or just rewrite everything to the index? – BenM Dec 16 '14 at 10:11
  • 2
    possible duplicate of [jquery: change the URL address without redirecting?](http://stackoverflow.com/questions/6478485/jquery-change-the-url-address-without-redirecting) – Alex Dec 16 '14 at 10:12
  • 1
    It sounds like you just need to configure the server to serve up your content under `/` instead of `/int/bdf/eng/`, since we have no idea how the content is generated at the moment, it is hard to say how to change it to be that way. Simply moving an `index.html` file to a different directory might do the job. – Quentin Dec 16 '14 at 10:13
  • its an extension from a cms system like wordpress that adds the parameters /xx/xx/xx to the url when visiting the start page...so i mean the url have to change it live...best case without reloading – Jim Dec 16 '14 at 10:16
  • Frankly, I'd solve this by "not caring". If you get a redirect - so what? The URL still works. It doesn't matter what is displayed to the user. If you want to change it in any vaguely sane way, you'll have to edit the CMS code. Since you haven't even told us what CMS it is, we can't help you with that. – Quentin Dec 16 '14 at 10:19
  • it was only a question if its possible without changing the extension... – Jim Dec 16 '14 at 10:21

1 Answers1

0

According to the W3C standards you can use the location hash property.

For an example URL like this:

http://www.example.com/test.htm#part2

The location.hash value would be: "#part2" and here is a JSFiddle that shows you how you can use that.

Manuel B.
  • 115
  • 7