title: AngularJS HTML5 Mode - How do direct links work without server specific changes?
body: <p><em>Note: This question could also read:</em></p>
  <blockquote>
  <p>How to support bookmarking of hashbang-less client side MVC frameworks
  in Java.</p>
  </blockquote>
  <p>I am transitioning an angular app that uses <code>hashtags</code> to one that is <code>html5mode</code>. I have successfully set</p>
  <pre><code>$locationProvider.html5Mode(true);
  </code></pre>
  <p>And all links from the landing page (index.html) work fine.</p>
  <p>The problem is, if partial URLs are referenced directly, I get a 404, naturally, since the server endpoint definitions aren't coupled to client side-defined routes.</p>
  <p>So without HTML5 we get non-SEO friendly hashbangs, but with it we cannot bookmark anything other than the landing page (the page that bootstraps angular).</p>
  <p>Why it works if requesting default landing page (index.html) first, ie htpp://mydomain.example/:</p>
  <ol>
  <li>Browser requests index.html from server</li>
  <li>Server returns index.html, and browser loads angular framework</li>
  <li>URL changes are sent to the client side router and the proper partial/s are loaded.</li>
  </ol>
  <p>Why it doesn't work if (ie) <code>http://mydomain.example/foo</code> is requested directly from the browser:</p>
  <ol>
  <li>Browser requests mydomain/foo from server.</li>
  <li>Resource doesn't exist</li>
  <li>Server returns 404</li>
  </ol>
  <p>Something is missing from this story, I just don't know what. Here are the only two answers I can see...</p>
  <ul>
  <li><strong>It's by design.</strong>  Is this how it is supposed to work? That users must always land on the client MVC framework's bootstrap page (usually index.html), and then navigate from there. This is not ideal because state cannot be saved and there is no way to bookmark... not to mention crawling.</li>
  <li><strong>Server solution.</strong>  Is this worked around with a server side trick? For example, on all requests, return index.html and immediately call router with additional context. If so, this is against the objective that AngularJS is completely client-side and seems like a hack.</li>
  </ul>