.htaccess重定向不适用于Angular 4 [英] .htaccess redirects not working with Angular 4
问题描述
我知道很多人都在问这个问题,但是我已经看了所有的答案,却无济于事。
I know a lot of people ask this, but I have looked at all the answers and nothing is working.
我确定问题是我需要创建.htaccess文件,并将其添加到dist,因为这是ISP控制台指南所说的。
I am sure the problem is I need to create a .htaccess file and add it to my dist because that is what the ISP console guide says to do.
我正在使用Angular cli和build命令:
I am using Angular cli and the build command:
ng build --aot --prod --base-href ./
我已将此.htaccess文件添加到我的app文件夹-与index.html文件相同的文件夹。这是.htaccess代码:
I have added this .htaccess file to my app folder - the same folder as my index.html file. This is the .htaccess code:
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中。我该怎么办?
I tried various snippets from various different answers on SO, I tried the snippet on the angular.io guide, I tried changing the base-href. Nothing seems to work and I can't even be sure it's being added properly to my dist in the build. What can I do?
推荐答案
与托管服务提供商的技术团队大惊小怪之后,他们确认了我的.htaccess文件没有通过我的FTP客户端上传。看起来我应该在构建后将其添加到dist文件夹中。他们添加的.htaccess文件的代码与我之前尝试过的版本之一相同,并且可以正常工作:
After making a big fuss with the technical team of my hosting provider, they confirmed my .htaccess file was not being uploaded via my FTP client. It looks like I should have added it to the dist folder after the build. The code for the .htaccess file they added is just the same as one of the versions I tried before and it works fine:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
这篇关于.htaccess重定向不适用于Angular 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!