【问题标题】:Angular 6 htaccess configuration for HTTPS websiteHTTPS 网站的 Angular 6 htaccess 配置
【发布时间】:2018-12-27 18:19:20
【问题描述】:

我刚刚在我的网站上安装了 SSL 证书,但之后我的应用程序的刷新功能被破坏并总是返回 404 错误:未找到 我更改了我的 .htaccess 文件,但总是出现同样的问题。

这是我在将我的网站升级到 HTTPS 之前的 .htaccess 文件(它工作正常)

<IfModule mod_rewrite.c>
    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>

<FilesMatch "\.(html|htm|js|json|css)$">
    <IfModule mod_headers.c>
        FileETag None
        Header unset ETag
        Header unset Pragma
        Header unset Cache-Control
        Header unset Last-Modified
        Header set Pragma "no-cache"
        Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
        Header set Expires "Mon, 10 Apr 1972 00:00:00 GMT"
    </IfModule>
</FilesMatch>

ErrorDocument 404 /dist/

升级到 HTTPS 后,我将其更改为这个(不起作用)

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# 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

<FilesMatch "\.(html|htm|js|json|css)$">
        <IfModule mod_headers.c>
                FileETag None
                Header unset ETag
                Header unset Pragma
                Header unset Cache-Control
                Header unset Last-Modified
                Header set Pragma "no-cache"
                Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
                Header set Expires "Mon, 10 Apr 1972 00:00:00 GMT"
        </IfModule>
</FilesMatch>

ErrorDocument 404 /dist/

提前感谢您的帮助

【问题讨论】:

    标签: angular apache .htaccess https


    【解决方案1】:

    我的错,这是 apache 配置文件的问题。

    当我使用 HTTP 协议时,virtualHost:80 包含选项 AllowOverride All 但是在 virtualHost:443 中它不包含这个选项,所以在我将它添加到这个 virtualHost 之后,它与 .htaccess 文件的第一个版本(看我的问题)。

    我把这个放在这里给有同样问题的人。

    【讨论】:

      猜你喜欢
      • 2013-06-15
      • 1970-01-01
      • 1970-01-01
      • 2020-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-02
      • 1970-01-01
      相关资源
      最近更新 更多