csf
csf

Reputation: 577

Apache to force certain URL for HTTP and all others go via https

First i have to say I found many answers for revise situation but not for this.

Apache to force certain URL for HTTP and all others go via https. Would like to get expert knowledge on following. Thanks for all of your time and appreciate that.

We have apache fronting tomcat in our production environment and we would like to enable https for all the incoming except for few pages and would like help on writing solid apache rewrite rule to do this . That is

  1. All incoming connection go via https except for some pages (/abc, /def, /ghi) to force http.

Any help. I came up with this with help of google  but its not working for http. All traffic goies to https

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/(/abc|/def|/ghi)
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} ^/(/abc|/def|/ghi)
RewriteRule ^(.*)$ http://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

Upvotes: 2

Views: 230

Answers (1)

Jon Lin
Jon Lin

Reputation: 143886

You have too many slashes in your condition to check against the %{REQUEST_URI}. Remove the ones inside the parentheses:

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/(abc|def|ghi)
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} ^/(abc|def|ghi)
RewriteRule ^(.*)$ http://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

Upvotes: 2

Related Questions