title: Best way to redirect to a hashed version of a URI?
body: <p>So all of the pages on my web application have URIs of the form <a href="http://www.example.com/#some-hash" rel="nofollow noreferrer">http://www.example.com/#some-hash</a> and the like. But of course, if the user visits <a href="http://www.example.com/some-hash" rel="nofollow noreferrer">http://www.example.com/some-hash</a> they should get redirected and experience the site in its usual glory.</p>
  
  <p>OK, no problem, right? Just write some kind of global HTTP request interceptor that auto-redirects anything to its hashed version.</p>
  
  <p>But that doesn't quite work, because the idea of visiting <a href="http://www.example.com/#some-hash" rel="nofollow noreferrer">http://www.example.com/#some-hash</a> is that the "frame" page (i.e., <a href="http://www.example.com/" rel="nofollow noreferrer">http://www.example.com/</a>) then Ajax-loads <a href="http://www.example.com/some-hash" rel="nofollow noreferrer">http://www.example.com/some-hash</a> into its inner frame. So the simple solution mentioned above runs into infinite loops when this Ajax happens, because Ajax requests at least should be allowed to get the unhashed version.</p>
  
  <p>Right now I have an unsatisfactory solution where all of my "sub pages" include</p>
  
  <pre><code>if (window.location.pathname != "/")
  {
      window.location.href = window.location.protocol + "//" + window.location.host + "/#" + window.location.pathname.substring(1);
  }
  </code></pre>
  
  <p>The biggest problem, besides code duplication (which is mitigated somewhat by using a script-combining framework), is that when the user visits <a href="http://www.example.com/some-hash" rel="nofollow noreferrer">http://www.example.com/some-hash</a>, the ugly unstyled, unscripted version of the page takes a second or two to load, and only <em>then</em> does the JavaScript redirect fire. No fun!</p>
  
  <p>So I'm looking for better solutions. Server-sided we're working on ASP.NET MVC 2, but this is somewhat agnostic. Maybe something like, append "?framed=true" to the requests when using Ajax, then do a server-sided redirect whenever non-root paths are directed that don't have framed=true in their querystring? I'm interested in how you'd solve this problem.</p>