How avoid 404 when using history API HTML5

492 views Asked by At

In SennaJS and EmberJS both using History API. How those libraries avoid 404 when a URL is pasted in address bar.

1

There are 1 answers

1
David Zorychta On BEST ANSWER

You have to modify your webserver and enable mod_rewrite. Then the server will take the request and forward it to your index file, and ember and SennaJS will parse the URL as you would expect.

For Apache you need to enable mod rewrite and edit your 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>

and nginx:

rewrite ^(.+)$ /index.html last;

see: http://readystate4.com/2012/05/17/nginx-and-apache-rewrite-to-support-html5-pushstate/