Redirect only one folder to HTTPS, all others to HTTP

14,816

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]
Share:
14,816
Newbie Aspiring Programmer
Author by

Newbie Aspiring Programmer

Updated on June 04, 2022

Comments

  • Newbie Aspiring Programmer
    Newbie Aspiring Programmer almost 2 years

    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!