Angular apache 上的路由返回内部服务器错误

Angular routing on apache is returning internal server error

我正在使用 PathLocationStrategy 并在 apache 上部署了我的 angular 应用程序。我的 angular 应用程序文件位于文件夹“teste”中,该文件夹位于文件夹“public_html”中。我已经更改了“public_html”中的 .htaccess 文件,但在重新加载页面时仍然出现内部服务器错误: “内部服务器错误 服务器遇到内部错误或配置错误,无法完成您的请求。 ..."

这是我的 .htaccess:

# php -- BEGIN cPanel-generated handler, do not edit
# Defina o pacote ~@~\ea-php73~@~] como a linguagem padrão de programação 
~@~\PHP~@~].
<IfModule mod_rewrite.c>
  AddHandler application/x-httpd-ea-php73 .php .php7 .phtml

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

  RewriteRule ^(.*) /index.html [NC,L]
</IfModule>
# php -- END cPanel-generated handler, do not edit

我做错了什么?还有什么事要做吗?

由于您要将 angular 应用程序部署到根托管文件夹的子文件夹中,即 public_hmtl,请首先使用以下命令构建应用程序。

ng build --prod --base-href=/teste/

这将在执行构建时将 index.html 中的应用程序基础设置为如下所示。

<base href="/teste/">

现在在 htaccess 文件的 RewriteRule 中定义子文件夹。

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

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