我想將所有請求重定向到https://www.example.com.
htaccess 代碼:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
我當前的代碼作業正常,但是當有人輸入http://example.com它時,301 redirect首先需要兩種方式,然后重定向https://example.com到https://www.example.com
我想http://example.com以https://www.example.com一個301 redirect。
uj5u.com熱心網友回復:
您可以使用以下命令將所有請求重定向到https://www單個請求中
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www
RewriteCond %{HTTP_HOST} ^(?:www\.)?(. )$
RewriteRule ^ https://www.%1%{REQUEST_URI} [L,R=301]
在測驗此新重定向之前,請確保創建瀏覽器快取資料。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/401304.html
標籤:html .htaccess ssl 重定向 https
