Apache 重定向 http 到 https

Apache 重定向 http 到 https

我嘗試啟動網站重定向,從 http 到 https。

的內容.htacces成立

RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
ErrorDocument 404 /centreon/index.html

當我添加這個時:

RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

httpd 重新載入或重新啟動後,http 到 https 的重定向不起作用。也許規則衝突?抱歉,我對這類規則很陌生。

關於全域配置,我把它放進去 10-centreon.conf-> RedirectMatch ^/$ /centreon

主站點不是虛擬主機

SSL設定檔得到<VirtualHost _default_:443>

非常感謝您的幫助

答案1

抱歉這個簡短的回答,這應該是一條評論,但我還不能發表評論。

您可以嘗試重定向所有進入 http 虛擬主機的流量,並且由於連接埠 80 和連接埠 443 由兩個不同的虛擬主機處理,因此規則僅適用於 http 流量。

答案2

感謝您的幫助,我終於明白了10-centron.conf

<VirtualHost *:80>
ServerName supervision
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
</VirtualHost>

相關內容