简体   繁体   中英

Apache HTTPS URL Rewrite

I've just started playing with Linux and Apache and got stuck on this.

I have this rewrite rule working fine:

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

How can I redirect to https applying these same rules?

Thanks!

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

If I understand your question correctly, you can implement this in your specific example.

Note that it is recommended to use a redirect inside your non-secure VirtualHost to your secure VirtualHost.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM