![](/img/trans.png)
[英]redirect http://www.domain.com to https://domain.com
[英]redirecting https://domain.com to https://www.domain.com
我最近將我的網站移至 HTTPS,我試圖將所有 http 流量強制為 https 和 www。 版本
即強制https://domain.com到https://www.domain.com
我有這個在我的htaccess以及所有HTTP到https的作品,除了從重定向https://domain.com到https://www.domain.com
我究竟做錯了什么?
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
你需要一個OR
條件:
RewriteEngine on
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.domain.com%{REQUEST_URI} [R=301,L,NE]
RewriteEngine on
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.example.com%{REQUEST_URI} [R=301,L,NE]
使用上述規則https://example.com沒有重定向到https://www.example.com 。 為此,我也在 apache ssl vhost 塊中添加了以下規則
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.exmple.com%{REQUEST_URI} [R=301,L,NE]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.