Been pulling my hair out over a certain issue. I can't seem to find out why my pushState router is not working on our development server while it works perfectly on 2 other real servers (staging and client's live domain) and it also works for my local MAMP server.
Here's my router:
jQuery(function(){
// define routes
var Router = Backbone.Router.extend({
routes: {
'': 'chrono',
':number': 'chrono',
':number/plus': 'chrono'
},
// load views
initialize: function() {
Backbone.history.start({
pushState: true,
hashChange: false // use html5 pushState with hashChange set to false
// to handle navigation of hash anchors
});
},
chrono: function(number) {
url = window.location.hash.split("/");
this.reset();
this.content = new chronoView();
if(number == undefined){
number = 0;
}
if(url[1]=="plus") {
this.content.showMiddleBox();
jQuery('#overlay2').show();
}
},
reset: function() {
if (this.content != undefined){
this.content.hide();
}
}
});
var Router = new Router;
});
My .htaccess
file on the non-working server does have quite a few engine re-write rules already, and the file itself is 200+ lines but here's what I deem to be the relevant parts:
# Block access to "hidden" directories whose names begin with a period. This
# includes directories used by version control systems such as Subversion or Git.
<IfModule mod_rewrite.c>
RewriteCond %{SCRIPT_FILENAME} -d
RewriteCond %{SCRIPT_FILENAME} -f
RewriteRule "(^|/)\." - [F]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 index.php
</IfModule>
# URL and hash rewrite for backbone
# Used for HTML 5 pushState support *NOT WORKING*
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index
RewriteRule (.*) index.html [L]
</ifModule>
/* EDIT */
After comparing the .htaccess
file of the non-working server against the working server.htaccess
I've not had any success, as both files were essentially the same except for some accounting for subfolder paths. I.e.:
Working server: RewriteRule ^(.*)$ index.php?/$1 [L]
Non-working server: RewriteRule ^(.*)$ dj24/index.php?/$1 [L]
And that's the only difference between the two files, but this makes sense because the client's version (working .htaccess) is hosted on subdomain with no subfolder, i.e. http://subdomain.ClientsDomain.com/
whereas our development server version hosts the project on a subfolder path to a subdomain, i.e. http://dev.Our_Domain.com/OurApplication
I'm starting to believe it's the subdomain + subfolder combo that's causing the issue. Any help with this would be appreciated. Thanks!