angular - http 到 https 重定向在使用 htaccess 的 Angular 6 中不起作用

标签 angular .htaccess

我正在尝试将我的网站重定向到 https://www使用 htaccess 301 永久重定向规则。

我在 Angular 6 构建版本的 htaccess 文件中使用以下代码。

路径:/mysite/dist/myfolder/.htaccess

RewriteEngine on
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.yourwebsite.com/$1 [R=301,L]


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

当我打开 https://example.com 时,上面的代码有效然后它重定向到 https://www.example.com 。这很好。

但是当我尝试打开 example.com 或 http://example.com 时那么它不会重定向到 https://www.example.com .

最佳答案

只需添加HTTPS重写规则即可。

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteCond %{HTTPS} off
  RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . index.html [L]
</IfModule>

关于angular - http 到 https 重定向在使用 htaccess 的 Angular 6 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52773422/

相关文章:

javascript - TypeScript Angular 2 响应订阅

angular - 使用 angularfire 过滤来自 Firestore 的数据

php - .htaccess 表示 PDF URL

php - 当用户下载文件时隐藏文件夹路径

javascript - 无法捕获从 Angular 4 中的子组件发出的事件

Angular 延迟加载模块 401

Angular 6 代码覆盖率......如何在应用程序的代码覆盖率中排除本地库?

php - .htaccess 无法在实时系统上运行

python - 使用 .htaccess 通过 Tornado 保护 Web 请求

apache - 重定向除白名单之外的所有 IP