title: $location / switching between html5 and hashbang mode / link rewriting
body: <p>I was under the impression that Angular would rewrite URLs that appear in href attributes of anchor tags within tempaltes, such that they would work whether in html5 mode or hashbang mode. The <a href="http://docs.angularjs.org/guide/dev_guide.services.$location" rel="noreferrer">documentation for the location service</a> seems to say that HTML Link Rewriting takes care of the hashbang situation.  I would thus expect that when not in HTML5 mode, hashes would be inserted, and in HTML5 mode, they would not.</p>
  
  <p>However, it seems that no rewriting is taking place.  The following example does not allow me to just change the mode.  All links in the application would need to be rewritten by hand (or derived from a variable at runtime.  Am I required to manually rewrite all URLs depending on the mode?</p>
  
  <p>I don't see any client-side url rewriting going on in Angular 1.0.6, 1.1.4 or 1.1.3.  It seems that all href values need to be prepended with #/ for hashbang mode and / for html5 mode.</p>
  
  <p>Is there some configuration necessary to cause rewriting? Am I misreading the docs? Doing something else silly?</p>
  
  <p>Here's a small example:</p>
  
  <p>
  </p>
  
  <pre><code>&lt;head&gt;
      &lt;script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.1.3/angular.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
      &lt;div ng-view&gt;&lt;/div&gt;
      &lt;script&gt;
          angular.module('sample', [])
              .config(
          ['$routeProvider', '$locationProvider',
              function ($routeProvider, $locationProvider) {
  
                  //commenting out this line (switching to hashbang mode) breaks the app
                  //-- unless # is added to the templates
                  $locationProvider.html5Mode(true);
  
                  $routeProvider.when('/', {
                      template: 'this is home. go to &lt;a href="/about"/&gt;about&lt;/a&gt;'
                  });
                  $routeProvider.when('/about', {
                      template: 'this is about. go to &lt;a href="/"/&gt;home&lt;/a'
                  });
              }
          ])
              .run();
      &lt;/script&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p></p>
  
  <p>Addendum: in re-reading my question, I see that I used the term "rewriting" without an abundance of clarity as to who and when I wanted to do the rewriting. The question is about how to get <strong>Angular</strong> to rewrite the URLs when it renders paths and how to get it to interpret paths in the JS code uniformly across the two modes.  It is <strong>not</strong> about how to cause a web server to do HTML5-compatible rewriting of requests.</p>