I have a site with only 3 URLs that need to be accessed via HTTPS. So I have 2 VirtualHost sections, one for HTTP (port 80) and the other for HTTPS (port 443).
Redirecting from HTTP to HTTPS is easy, I basically have this in the HTTP section:
RewriteEngine on
RewriteRule ^/wp-admin/(.*)$ https://%{SERVER_NAME}/wp-admin/$1 [R=permanent,L]
RewriteRule ^/wp-login.php$ https://%{SERVER_NAME}/wp-login.php [R=permanent,L]
RewriteRule ^/wp-register.php$ https://%{SERVER_NAME}/wp-register.php [R=permanent,L]
So whenever user wants to log in or register he will be redirected to a secure site. However, once the user has logged on, I don't want him to stay on HTTPS. Obviously, I could change WP code to redirect back to HTTP, but unfortunately that's not an option.
So the question is, how do I define RewriteRules in the HTTPS so that all requests will be redirected to HTTP only if they are not the following URLs:
/wp-admin/(.*)$
/wp-login.php$
/wp-register.php$
I hope that makes sense...
You can easily check the
%{REQUEST_URI}
with a RewriteCond. You can also check%{HTTPS}
to find out whether the client useshttp://
orhttps://
to access your site.