[英]HTTPS redirect from non www to non www
我有一個非 WWW 域,當我嘗試設置重定向到 HTTPS 時,從http://www.examle.com重定向到https://www.example.com對我有用,但http://example. com不適用於https://example.com 。 當前的 htaccess 是:
RewriteEngine On
RewriteCond %{REQUEST_URI} .*index\.html/?$ [NC]
RewriteRule ^(.*)index\.html/?$ https://$1 [R=301,L,NC]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
RewriteCond $1 !index\.php
RewriteCond $1 !^assets
RewriteCond $1 !^robots.txt
RewriteCond $1 !^sitemap.xml
RewriteRule ^(.*)$ index.php [L]
你能告訴我我做錯了什么嗎? 謝謝
更新:
當前 .htaccess
RewriteEngine On
RewriteCond %{REQUEST_SCHEME} =http
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
RewriteCond %{REQUEST_URI} .*index\.html/?$ [NC]
RewriteRule ^(.*)index\.html/?$ https://$1 [R=301,L,NC]
RewriteCond $1 !index\.php
RewriteCond $1 !^assets
RewriteCond $1 !^robots.txt
RewriteCond $1 !^sitemap.xml
RewriteRule ^(.*)$ index.php [L]
您正在使用此規則進行https
重定向:
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
第一個條件為%{HTTP_HOST} ^www\\.
這意味着它只會匹配以www.
開頭的主機名www.
因此你不會重定向到http://example.com/
。
您可以改用此重定向規則:
RewriteCond %{HTTPS} !on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,NE,R=301]
這將執行以下重定向:
http://example.com/ => https://example.com/
http://www.example.com/ => https://www.example.com/
在測試之前,請確保清除瀏覽器緩存。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.