Backbone.js PushState routes .htaccess only working as hash but nowhere else
I have a website domain.com for example. I have backbone.js with pushstate and fallback and when I goto domain.com/about it loads up the index.html page and pushstates to about. everything is working. but if i want to goto a directory with a page inside like: www.domain.com/bio/moreinfo for example, it does not work and throws a invalid page. if i do it in IE it works fine. my htaccess file has the following:
RewriteEngine on # html5 pushstate (history) support: <ifModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !index RewriteRule (.*) index.html [L] </ifModule>
if i navigate directly to the page domain.com/bio/moreinfo it craps out (i think because my server wants to goto the bio directory? or maybe I need to actually control the routes in backbone differently? its just that it works on bangs so it has to be some weird push state directory thing where #bio/info is not the same to apache as /bio/info . any help is appreciated.
Answers
well using the answer in another suggested post, which was to do <base href="/" /> in the index.html file. This actually made the sub directories in my pushState work! just it was suggested.. but then in return it broke my IE, but i fixed it by putting extra code in my INIT of backbone
Backbone.history.start({ pushState: Modernizr.history, silent: true }); if(!Modernizr.history) { var rootLength = Backbone.history.options.root.length; var fragment = window.location.pathname.substr(rootLength); var search = window.location.search; Backbone.history.navigate('/#' + fragment + search, { trigger: true }); } else { Backbone.history.loadUrl(Backbone.history.getFragment()) }