在apache中将所有http请求重定向到https

在apache中将所有http请求重定向到https,apache,Apache,我在服务器端使用Apache。我想将所有到达服务器的HTTP请求重定向到HTTPS 我的问题: 如何为此配置httpd.conf? 例如:假设用户输入了 我想将其重定向到这需要mod_rewrite,但能够保留查询字符串: RewriteEngine On RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L] 这在服务器上不起作用,而且更轻: RedirectMatch permanent ^(.*)$ https:

我在服务器端使用Apache。我想将所有到达服务器的HTTP请求重定向到HTTPS

我的问题: 如何为此配置httpd.conf? 例如:假设用户输入了
我想将其重定向到这需要
mod_rewrite
,但能够保留查询字符串:

RewriteEngine On
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
这在服务器上不起作用,而且更轻:

RedirectMatch permanent ^(.*)$ https://doc.com/$1
如果您只想将所有nōn-HTTPS请求重定向到起始页,请使用:

RedirectMatch permanent . https://doc.com/
RedirectMatch permanent . https://doc.com/