Vitaly Mirsky
Vitaly Mirsky

Reputation: 77

Exceptions in http to https redirect in htaccess

I have the following code in my htaccess and it works fine:

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www.host\.com*
RewriteRule ^(.*)$ https://host.com/$1 [L,R=301]

but I have one derictory, that I shouldn`t be redirected i.e. should be accessed through http, e.g. host.com/nossl/... what should add to my htaccess? Thanks.

Upvotes: 0

Views: 355

Answers (1)

anubhava
anubhava

Reputation: 786051

You can use a negative pattern in RewriteRule like this:

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www.host\.com$ [NC]
RewriteRule !^nossl(/.*)?$ https://host.com%{REQUEST_URI} [L,R=301,NC,NE]

Upvotes: 1

Related Questions