Redirect only one folder to HTTPS, all others to H

2019-04-01 22:49发布

问题:

I apologize in advance for asking something that's been answered several times on SO, but I haven't been able to modify any of the answers to work for this case.

I have a /secure/ folder that I need to redirect to HTTPS. Everything outside of that folder should be redirected to HTTP.

I plan on using absolute links for navigation through my site, but I need to guarantee that the pages in the /secure/ folder are only viewable over HTTPS. For the other pages it doesn't really matter, but I'd prefer them only viewable over HTTP because I'm on shared hosting and the server is already slow as it is.

Thank you very much!

回答1:

Adapted an example on this page this page. See if the following works for you.

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteCond %{REQUEST_URI} secure 
RewriteRule ^(.*)$ https://www.example.com/secure/$1 [R,L]