简体   繁体   English

使用历史记录API HTML5时如何避免404

[英]How avoid 404 when using history API HTML5

In SennaJS and EmberJS both using History API. SennaJS和EmberJS中,都使用History API。 How those libraries avoid 404 when a URL is pasted in address bar. 当将URL粘贴到地址栏中时,这些库如何避免404。

You have to modify your webserver and enable mod_rewrite. 您必须修改您的Web服务器并启用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. 然后,服务器将处理该请求并将其转发到您的索引文件,并且ember和SennaJS将按您期望的那样解析URL。

For Apache you need to enable mod rewrite and edit your vhost: 对于Apache,您需要启用mod重写并编辑您的虚拟主机:

<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: 和Nginx:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM