首页 > 解决方案 > 使用 apache 重写的 Angular7 无法正常工作

问题描述

我有我的角度应用程序7.1.4在 apache2.4.10服务器上运行。我PathLocationStrategy用来路由我的网址。

这是我的 index.html 文件的一瞥

<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<meta http-equiv="Cache-control" content="no-cache, no-store, must-revalidate">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="0" />
<title>Intranet</title>
<base href="/">

.htaccess 文件

选项 +FollowSymlinks

重写引擎开启

RewriteCond %{REQUEST_FILENAME} -f [OR]

RewriteCond %{REQUEST_FILENAME} -d

重写规则 ^ - [L]

重写规则 ^ /index.html [L]

问题是,如果我的网址看起来像

http://intranet.company.com/app/myspace?id=favorites

阿帕奇重定向到

http://intranet.company.com/index.html?id=favorites

并且我的目标页面没有显示。

知道我的 URL 都以BASE_URI/app/...

标签: mod-rewriteurl-rewritingangular7apache2.4angular7-router

解决方案


删除 index.html 的 / 前面

   RewriteRule ^ index.html [L]

推荐阅读