【问题标题】:Angular4 deploy server apache routeAngular4部署服务器apache路由
【发布时间】:2018-02-01 21:58:49
【问题描述】:

我有一个在 CentO 上运行的 apache 服务器,我想在这个服务器上部署我的 Angular4 项目。该项目部署在 /var/www/html 文件夹中。它工作得很好,除了路由部分。当我从基本 index.html 刷新或访问不同的 URL 时,出现 404 错误。

我点击了这个链接:https://angular.io/guide/deployment#routed-apps-must-fallback-to-indexhtml,但没有任何改变。

我的 .htaccess :

RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
RewriteRule ^ /index.html

我的 /etc/httpd/conf/httpd.conf 文件的一部分:

<Directory "/var/www/html">
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

404 错误总是在这里。 我不知道如何解决这个问题。我做错什么了吗 ?提前致谢

【问题讨论】:

    标签: angular apache .htaccess url-routing


    【解决方案1】:

    它在根目录下使用这个 .htaccess :

    <IfModule mod_rewrite.c>
        RewriteEngine on
        RewriteCond %{REQUEST_FILENAME} -f [OR]
        RewriteCond %{REQUEST_FILENAME} -d
        RewriteRule ^ - [L]
        RewriteRule ^ index.html [L]
    </IfModule>
    

    【讨论】:

      【解决方案2】:

      我不确定你的重写配置是否正确(对Apache配置了解不多)。

      我只知道您需要将 404 路由重定向到 index.html。因此,如果有一种特殊的方法可以仅重定向 404 路由,您可以尝试重写它。

      【讨论】:

        猜你喜欢
        • 2014-08-14
        • 1970-01-01
        • 2019-08-08
        • 2018-11-30
        • 1970-01-01
        • 2020-03-24
        • 2013-04-13
        • 1970-01-01
        • 2020-01-18
        相关资源
        最近更新 更多