I wanted to extend my question with regards to this question. I was able to get pushstate to work correctly within my Backbone application. So when visiting my application and navigating links, I am redirected to localhost:8000/page instead of localhost:8000/#page. Now my issue becomes apparent when reloading localhost:8000/page. Obviously my server will throw an error because it cannot find the specified page. As opposed to localhost:8000/#page, which will call the correct route. Now lets say my application is at the following localhost:8000/index.html. Would I then have to request all routes to be redirected to localhost:8000/index.html. What is considered the correct way to do this? I found this gist based on a node.js server configuration for Backbone and pushstate. Quick look and seems as though all requests are just being redirected to the application file (index.html). Is this correct? Any luck with IIS?
Asked
Active
Viewed 597 times
1
-
1Ideally, you can bootstrap your collections or models server side if the users entry point is /page instead of having to redirect to /index.html (That is if you're dealing with data). /page can still respond with the same layout template as /index.html but with additional data bootstrapped thats specific to /page. – Mark Sep 06 '12 at 17:30
1 Answers
0
Basically you need some rewrite rules in your Apache or Nginx.
Apache Vhost:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
Nginx:
rewrite ^(.+)$ /index.html last;
For actual API calls I serve them on a subdomain, like api.site.com. To do this you may need to enable CORS.
I talk about it in more depth on this blog entry: http://readystate4.com/2012/05/17/nginx-and-apache-rewrite-to-support-html5-pushstate/

Mauvis Ledford
- 40,827
- 17
- 81
- 86