apache - .htaccess 重定向不适用于 Angular 4

标签 apache angular .htaccess redirect

我知道很多人问这个问题,但我查看了所有答案,但没有任何效果。

我确定问题是我需要创建一个 .htaccess 文件并将其添加到我的 dist,因为这是 ISP 控制台指南所说的。

我正在使用 Angular cli 和构建命令:

ng build --aot --prod --base-href ./

我已将此 .htaccess 文件添加到我的应用程序文件夹 - 与我的 index.html 文件相同的文件夹。这是 .htaccess 代码:

RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]

    RewriteRule ^(.*) /index.html [NC,L]

我在 SO 上尝试了各种不同答案的各种片段,我尝试了 angular.io 指南上的片段,我尝试更改 base-href。似乎没有任何效果,我什至无法确定它是否已正确添加到构建中的 dist 中。我能做什么?

最佳答案

在与我的托管服务提供商的技术团队大惊小怪之后,他们确认我的 .htaccess 文件没有通过我的 FTP 客户端上传。看起来我应该在构建后将它添加到 dist 文件夹中。他们添加的 .htaccess 文件的代码与我之前尝试过的版本之一相同,并且运行良好:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>

关于apache - .htaccess 重定向不适用于 Angular 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45803855/

相关文章:

linux - 与另一个 Web 服务器一起运行 Apache?

java - Jmeter - java 编码。如何获取输出数据?

angular - 在 IONIC 3 中,如何在 ios 上上传 word 或 pdf 等文件?

angular - 输入更改时不调用子组件内的管道

.htaccess - 为多个域重写为 www 和 https 并不总是有效

regex - ^ 字符无法在 htaccess 中进行 mod 重写

apache - 为什么我的 UrlRewriteFilter 不能在 Tomcat 上运行?

javascript - Angular => react 形式 : disable button when it encounters an empty input field

.htaccess - mod_rewrite 在大写目录上失败

php - Node js/Express 替代 LAMP