【发布时间】:2018-10-21 13:27:30
【问题描述】:
几天前,我使用以下代码在我的 angular(1.5.8) 应用上打开了 html 5 模式:
$locationProvider.html5Mode({enabled:true,requireBase:true}).hashPrefix('!');
后来我读到configuring apache server for html5 mode with ui-router。
做完这些设置后,我面临2个问题:
- 浏览器重新加载,重定向到每个深层嵌套应用链接的主页。
- 任何来自外部(通过电子邮件)的链接总是重定向到主页。
我玩过
- mod_rewrite as-in 在 apache 上使用
<Directory>、FallbackResource。 - 更改 index.html 中资产的路径(使用相对 URI 和完全限定 URI)
- 添加/删除 base HTML 标记。 (尝试使用“/”、“
<sitename>”等选项)
但我还没有克服这些问题。
这是我本地主机上的详细设置:
- 我正在通过虚拟主机(而不是 .htaccess)部署到 apache。
- 我的部署目录是 /Users/
<name>/Sites/<sitename>(我在 mac OS 上) -
我的 index.html 部分如下:
<head> <base href="/"> <!-- SPELLS 1--> <script src="/js/jquery.min.js"></script> <script src="/js/bootstrap.min.js"></script> <script src="/js/angular.min.js"></script> <!-- more scripts / css et al --> </head> -
我的 Apache(2.4.28) 配置如下:
<VirtualHost *:80> ServerName <servername> DocumentRoot "/Users/<name>/Sites/<sitename>" #LogLevel debug LogLevel debug rewrite:trace6 RewriteEngine on RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR] RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d RewriteRule ^ - [L] RewriteRule ^ index.html [L] Options Indexes FollowSymLinks Require all granted </VirtualHost>
任何人都可以帮助我进行确切的设置吗?
【问题讨论】:
-
我最接近它的工作是:: 深层嵌套的 url 粘在浏览器上(它没有重定向到 index.html)但是 apache 返回 index.html 作为对所有的响应我的资产(js/css),并将它们的 mime 类型更改为 text/html。
-
相同的demo HTML5 模式中断With html5 mode Apache 404 Not Found
标签: angularjs html apache mod-rewrite angular-ui-router