Apache http to https except 2 paths

Dennie
Dennie used Ask the Experts™
on
Hi,

I've got this rewrite rule to redirect all http request to https
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

Open in new window


I want to make an exception for 2 paths (/a and /b). These paths can only be accessed over HTTP. How do I do this?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2004

Commented:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} !^/?(patha|pathb)
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

Open in new window

Author

Commented:
Thanks, but how do I force that those 2 exception paths can only be accessed over HTTP?
Top Expert 2004
Commented:
You will need a second rule to force HTTP for those two:

RewriteCond %{HTTPS} =on
RewriteCond %{REQUEST_URI} ^/?(patha|pathb)
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial