问题
I'm trying to get backbone.js's router to work with my XAMPP apache server on localhost.
I need to prevent apache from evaluating the directory paths that are supposed to go to the router and just forward everything to /test_backbone/index.html
. I've tried everything that I could find, nothing works.
Currently, I have this in httpd.conf file:
# html5 pushstate (history) support:
<ifModule mod_rewrite.c>
Options +FollowSymLinks
IndexIgnore */*
# Turn on the RewriteEngine
RewriteEngine On
# Rules
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /test_backbone/index.html
</ifModule>
I've also tried this:
# 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>
I was under the impression that some of those lines are supposed to say to load the static file if it exists, but none of my javascript files are being loaded, everything just goes back to /test_backbone/index.html
I've also tried .htaccess
files. For all I know I'm not even putting this code in the right place.
Any help would be greatly appreciated!
回答1:
Your configuration should work. When modifying httpd.conf
you need to restart apache
No need for restart when modifying .htaccess
.
Just in case, try to add the '[L]' flag to the Rewrite Rule in the httpd.conf
, so it stops processing more rules after that match.
来源:https://stackoverflow.com/questions/11404567/backbone-js-router-using-pushstate-with-xampp-apache-server-on-localhost