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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.