为具有HTML 5历史记录模式的Progressive Web App添加HTTPS重定向

问题描述 投票:0回答:1

我有一个使用Vue CLI 3构建的渐进式Web应用程序,当前正在使用HTML 5历史记录模式。我遵循了documentation to add the necessary configuration to the .htaccess,但是此示例不涵盖重定向到HTTPS。这就是我所拥有的:

<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将所有请求重定向到HTTPS的堆栈溢出响应,但这会导致无限循环的重定向循环。因此,我需要将非HTTPS请求重定向到HTTPS,同时仍然遵守index.html重定向。

.htaccess https progressive-web-apps vue-cli-3
1个回答
0
投票

[经过进一步的研究,我可以通过在.htaccess文件前添加一些特定于HTTPS的配置来解决我的问题。所以现在我的文件看起来像这样:

<IfModule mod_rewrite.c>
  RewriteEngine On

  RewriteCond %{HTTP:X-Forwarded-Proto} !=https
  RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,N]

  RewriteBase /
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.html [L]
</IfModule>
© www.soinside.com 2019 - 2024. All rights reserved.