【问题标题】:AngularJS - Enable HTML5 Mode Page Refresh Without 404 Errors [duplicate]AngularJS - 在没有 404 错误的情况下启用 HTML5 模式页面刷新 [重复]
【发布时间】:2018-08-25 04:55:07
【问题描述】:

我还尝试通过将 ui-routing 中的 $locationProvider.html5Mode(true); 和 base href 设置为 <base href="http://localhost/rootfoldername/"> 来删除哈希,但刷新时会出现 404 错误

请帮帮我...

【问题讨论】:

标签: angularjs html angular-ui-router


【解决方案1】:

正如其他人所说,启用 html5 模式并添加 baseURL 就可以解决问题,但是仍然缺少一个难题,那就是服务器的重写规则配置。

抛出 404 的原因是服务器没有将所有路由重定向到 angularJS 应用程序。这就是重写规则出现的地方。

对于 Apache:How to rewrite url in apache htaccess for angularjs app

对于 IIS:How do I configure IIS for URL Rewriting an AngularJS application in HTML5 mode?

【讨论】:

  • 您好尝试将重写代码放入 htaccess 中,但刷新时仍然出现相同的 404 错误。RewriteEngine on RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*$ - [NC,L] RewriteRule ^(.*) /index.html [NC,L]
  • 确保重写规则指向的 /index.html 确实存在并且包含 Angular 应用程序。如果这仍然不起作用,您可能需要在您的问题中添加其他信息,以便我们可以进一步帮助您,甚至可能是 404 错误页面的屏幕截图。
  • 我的代码结构:- apache>htdocs>projectname>index.html 和 .htaccess 都存在,有错误请告诉我。
猜你喜欢
  • 2016-10-15
  • 1970-01-01
  • 1970-01-01
  • 2017-10-31
  • 2019-04-30
  • 1970-01-01
  • 1970-01-01
  • 2018-08-26
  • 2016-05-25
相关资源
最近更新 更多