
我的 .htaccess 檔案不會將我的網域從 HTTP 重定向到 HTTPS。我的頁面被重定向到 HTTPS,但不是我的網域。
您知道什麼可能導致此問題嗎?
RewriteEngine On
RewriteCond %{HTTP_HOST} ^maghreb-secours\.com [NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}
php_value upload_max_filesize 200M
php_value post_max_size 200M
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
答案1
看起來有些東西正在將請求重定向到您的頂點到主機www
,而您的RewriteCond
配置僅在頂點上工作(^maghreb-secours
而不是^www.maghreb-secours
)
$ curl -s --head http://maghreb-secours.com/ | grep -e "^HTTP" -e "^Location:"
HTTP/1.1 301 Moved Permanently
Location: http://www.maghreb-secours.com/
$ curl -s --head https://maghreb-secours.com/ | grep -e "^HTTP" -e "^Location:"
HTTP/1.1 301 Moved Permanently
Location: https://www.maghreb-secours.com/
$ curl -s --head http://www.maghreb-secours.com/ | grep -e "^HTTP" -e "^Location:"
HTTP/1.1 200 OK
$ curl -s --head https://www.maghreb-secours.com/ | grep -e "^HTTP" -e "^Location:"
HTTP/1.1 200 OK
另外,我不確定是否需要反斜線來轉義主機名稱中的點。
也許這會起作用(包括頂點,以防您的配置發生變化)?
RewriteEngine on
RewriteCond %{HTTPS} != on
RewriteCond %{SERVER_NAME} =www.maghreb-secours.com [OR]
RewriteCond %{SERVER_NAME} =maghreb-secours.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]