我有一个带有http和https服务的apache反向代理服务器。我想将http重定向到https强制。我该怎么配置配置文件?
答案 0 :(得分:3)
推荐使用VirtualHost也更安全:
<VirtualHost *:80>
ServerName www.example.com
Redirect permanent / https://www.example.com/
</VirtualHost>
或
<VirtualHost *:80>
ServerName www.example.com
Redirect permanent /login https://www.example.com/login
</VirtualHost>
另一种方法是使用mod_rewrite:
RewriteEngine On
# This will enable the Rewrite capabilities
RewriteCond %{HTTPS} !=on
# This checks to make sure the connection is not already HTTPS
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
# This rule will redirect users from their original location, to the same location but using HTTPS.
# i.e. http://www.example.com/foo/ to https://www.example.com/foo/
# The leading slash is made optional so that this will work either in httpd.conf
# or .htaccess context
正如我所说,Apache建议使用VirtualHost配置。
示例取自: