Created
July 29, 2021 09:05
-
-
Save ThijsFeryn/999747408c7a4a6835118a4dc457ee57 to your computer and use it in GitHub Desktop.
Redirect to the www hostname in Varnish
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vcl 4.0; | |
import std; | |
sub vcl_recv { | |
if (!req.http.X-Forwarded-Proto) { | |
if(std.port(server.ip) == 443) { | |
set req.http.X-Forwarded-Proto = "https"; | |
} else { | |
set req.http.X-Forwarded-Proto = "http"; | |
} | |
} | |
if (req.http.Host !~ "^www\.") { | |
return (synth(301, req.http.X-Forwarded-Proto + "://www." + req.http.Host + req.url)); | |
} | |
} | |
sub vcl_synth { | |
if (resp.status == 301 || resp.status == 302) { | |
set resp.http.Location = resp.reason; | |
set resp.reason = "Moved"; | |
return (deliver); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment