http到https重定向使用htaccess在角度6中不起作用

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

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

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

路径:/ mysite/dist/myfolder/.htaccess代码:RewriteCond上的RewriteEngine%{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
2个回答
2
投票

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

0
投票

试试这个:

<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>
© www.soinside.com 2019 - 2024. All rights reserved.