0

My question is similar to this one, but my goal is to make the hashbang URLs silently redirect to the html5Mode style. I mean, when

example.com/#!/hello

gets entered, it should be silently changed to

example.com/hello

in order for existing links to stay valid. Compatibility with old browsers doesn't matter (as AFAIK everything supported by angularjs 1.3 works with the html5Mode).

Maybe I'm just misunderstanding the answer, but I can't see it there. I've got the html5Mode working without problems, but I sort of want two in one.

Community
  • 1
  • 1
maaartinus
  • 44,714
  • 32
  • 161
  • 320
  • url fragments are not sent to the server by the browser. there's NO way for mod_rewrite to change that url, because the `#!/hello` portion would never get sent to the server in the first place. – Marc B May 27 '15 at 16:59
  • @MarcB Sure, but I wanted angularjs to do it, not the server. More exactly 1. both URLs should work the same. 2. instead of the former, the latter should be displayed. The server returns the right content already (it sort of ignores the `pathInfo`). – maaartinus May 27 '15 at 17:16

2 Answers2

1

That's how it's working in mine and I'm not doing anything special? If I type mysite.com/angularapp/#/accounts/29 using Chrome, it gets replaced with mysite.com/angularapp/accounts/29

My routing config contains:

  function($locationProvider) {
    $locationProvider.html5Mode(true).hashPrefix("");
  }

I'm on Angular 1.2.21, I'm not sure if that behavior would have changed on 1.3.x.

Nicholas Hirras
  • 2,592
  • 2
  • 21
  • 28
0

You can do it manually in JS with something liek this:

window.location.replace(
    window.location.href.replace(new RegExp("^([^?]+/)#!/(.*)$"),
        function (all, s1, s2) { 
            return s1 + s2; 
        }
    )
);
vbence
  • 20,084
  • 9
  • 69
  • 118