Redirect all content from HTTP to HTTPS

By 8th August 2014September 15th, 2020No Comments

If you want to ensure that every page on your site is served over HTTPS, you should add the following rewrite rules, replace with your SSL enabled domain

In ___general/,

# Redirect all content to HTTPS
set $redirect "0";
if ($host ~* "^(www\.)?$") { set $redirect "go"; }
if ($my_http = http)                  { set $redirect "go${redirect}"; }
if ($remote_addr ~ 172.16.0.(6[0-9])) { set $redirect "0"; }
if ($request_method = PURGE)          { set $redirect "0"; }
if ($redirect = "gogo") {
  rewrite ^(.*)$$1 permanent;

! By default, Nginx will assume all relative redirects are HTTP. So if you have any rewrite rules, ensure they contain the full scheme, domain and path