Apache HTTPS URL重写

时间:2017-09-11 21:40:45

标签: linux apache ubuntu mod-rewrite url-rewriting

我刚刚开始玩Linux和Apache,并且坚持这个。

我有这个重写规则正常工作:

RewriteEngine on
RedirectMatch ^/$ /myserver/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /myserver/ [R]

如何重定向到https应用这些相同的规则?

谢谢!

1 个答案:

答案 0 :(得分:0)

On the Apache wiki:

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

如果我理解你的问题,你可以在你的具体例子中实现这个。

请注意,建议您将非安全VirtualHost中的重定向用于安全的VirtualHost。

相关问题