AngularJS - 删除 Hashbang 后重新加载页面时出现 404 错误

AngularJS - 404 error on page reload after Hashbang removal

使用

从我的路线中删除 hashbang 后

$locationProvider.html5Mode(true);

现在访问页面时,例如 "domain.com/download",它会起作用。但是如果我重新加载这个确切的页面,它会给我一个 404 错误。像 "domain.com/download" 这样的链接只能通过输入 "domain.com/#!/download" 打开。加载后,它会再次将我重定向到正常的 "domain.com/download" 页面。

我使用 v1.3.2 进行路由,使用 v1.6.3 进行其他操作(不要问我为什么不制作这个网站,哈哈)。

AngularJS Documentation 是这么说的:

Using this mode requires URL rewriting on server side, basically you have to rewrite all your links to entry point of your application (e.g. index.html). Requiring a tag is also important for this case, as it allows AngularJS to differentiate between the part of the url that is the application base and the path that should be handled by the application.

您必须将 .htaccess 更改为:

RewriteEngine On 
Options FollowSymLinks

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /#/ [L]