Reputation: 301
I want to redirect to HTTPS all urls which are not secure, except a custom url which includes various parameters.
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} !^/code-validator/?code=
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
So http://example.com/code-validator/?code=123 or any parameter on this url will not be redirected to HTTPS.
Upvotes: 1
Views: 53
Reputation: 785108
Use THE_REQUEST
instead of REQUEST_URI
to be able to:
REQUEST_URI
only matches URI without query stringYour rule can be:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{THE_REQUEST} !/code-validator/\?code= [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
Make sure to keep this rule as your topmost rule and also clear old browser cache.
Upvotes: 1