无法在实时服务器上的生产环境中部署 Angular 4

Not able to deploy Angular 4 in production on live server

我试过了 this answer 并且可以确认 mod_rewrite 在我的主机上启用

并且我尝试了来自各种答案和站点的以下 .htaccess 配置,但是 none helped.I 无法调试问题所在。

From the official site:

RewriteEngine On
    # If an existing asset or directory is requested go to it as it is
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
    RewriteRule ^ - [L]
    # If the requested resource doesn't exist, use index.html
RewriteRule ^ /index.html

来自一些要点

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

还有很多其他人,但都给出了 404 错误。任何调试它的方法。 我正在使用 ng build --prod 创建一个 dist,然后在 dev.example.com 上托管并尝试访问 dev.example.com/home,从 dev.example.com 访问时可用 可能是由于子域?

试试这个配置:

 RewriteEngine on
    # Don't rewrite files or directories
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    # Rewrite everything else to index.html
    RewriteRule ^ index.html [L]

我确认这不是子域问题。在尝试了大量 .htacess 文件后,我找到了 RewriteBase,将其添加到您的基本路径,假设您的基本路径是 /dev/ 添加 Rewritebase /dev/ 并且不要忘记添加 Options Indexes FollowSymLinks .

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

如果您遇到基本路径问题,请查看此问题 这个答案 他们肯定会解决您在 apache 服务器上的部署相关问题

我在我的目录

上丢失了 httpd.conf、AllowOverride All
<Directory "/var/www/html">
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>