So all of the pages on my web application have URIs of the form http://www.example.com/#some-hash and the like. But of course, if the user visits http://www.example.com/some-hash they should get redirected and experience the site in its usual glory.
OK, no problem, right? Just write some kind of global HTTP request interceptor that auto-redirects anything to its hashed version.
But that doesn't quite work, because the idea of visiting http://www.example.com/#some-hash is that the "frame" page (i.e., http://www.example.com/) then Ajax-loads http://www.example.com/some-hash 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.
Right now I have an unsatisfactory solution where all of my "sub pages" include
if (window.location.pathname != "/")
{
window.location.href = window.location.protocol + "//" + window.location.host + "/#" + window.location.pathname.substring(1);
}
The biggest problem, besides code duplication (which is mitigated somewhat by using a script-combining framework), is that when the user visits http://www.example.com/some-hash, the ugly unstyled, unscripted version of the page takes a second or two to load, and only then does the JavaScript redirect fire. No fun!
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.