angular - http 到 https 重定向在使用 htaccess 的角度 6 中不起作用
问题描述
我正在尝试使用 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。
解决方案
只需添加 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>
推荐阅读
- virtual-memory - TLB 和页表的参考位同步
- swift - 在 Swift、LinearGradient 和 Form - 背景重叠
- c++ - Embree: stream mode - how does gather and scatter work and what are pid and tid?
- node.js - Apollo 上传文件,createReadStream 不是函数
- .net-core - 无法从 Graph API 调用中获取组的显示名称 (sAMAccountName)
- flutter - Flutter NullSafety 在显示和更改 modalProgressHUD 后无法推送页面
- html - 我的文本框类似乎没有响应我的 CSS
- sql - 如何优化 postgres 中的交叉日期范围查询
- r - 在 MacOS Big Sur 上使用 brew 安装 R 时出现校验和错误
- postgresql - Postgres中的替换变量