【问题标题】:http to https redirection is not working in angular 6 using htaccesshttp 到 https 重定向在使用 htaccess 的角度 6 中不起作用
【发布时间】:2019-03-17 07:47:40
【问题描述】:

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

我在 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

【问题讨论】:

标签: angular .htaccess


【解决方案1】:

只需要添加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>

【讨论】:

    【解决方案2】:

    试试这个:

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

    【讨论】:

      猜你喜欢
      • 2023-03-03
      • 2016-04-12
      • 2018-09-08
      • 1970-01-01
      • 2013-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多