我正在尝试将我的网站重定向到 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/