I'm trying to get Nginx to rewrite incoming requests to a site my server prefixed with https://
to http://
(this is because a CMS used on this site forces URIs instead of relative paths -- essentially breaking the whole site by making images, scripts, and stylesheets unavailable).
I'm currently trying to retrofit an existing directive put in place by a predecessor, but I find myself limited by my knowledge of Nginx config syntax. Here's the code:
if ($ssl_protocol = "") {
rewrite ^ https://$http_host$request_uri? permanent;
}
I've current commented this code out to prevent forcible rewrites of http://
to https://
, but I can't reverse the process without breaking the site. Here's what I've tried so far:
if ($ssl_protocol = "https") {
rewrite ^ http://$http_host$request_uri? permanent;
}
and
# also tried ($ssl_protocol != "")
if (!($ssl_protocol = "")) {
rewrite ^ http://$http_host$request_uri? permanent;
}
The first one doesn't seem to have an effect. The HTML sent to the client still makes HTTPS requests that aren't being rewritten.
The second snippet doesn't appear to have any effect either - if I understand correctly (although I'm still somewhat surprised), Nginx doesn't support boolean negation.
What would be the best way (or a working way) to do this?
EDIT: I've tried adding the code from @NathanC's answer; however, this unconditional rewrite causes a redirect loop. Help is still appreciated.