Skip to content

Instantly share code, notes, and snippets.

@ssm
Created February 22, 2016 14:11
Show Gist options
  • Save ssm/51b4fc7151207a0afbd1 to your computer and use it in GitHub Desktop.
Save ssm/51b4fc7151207a0afbd1 to your computer and use it in GitHub Desktop.
sub redirect_to_https {
if (std.port(local.ip) == 80) {
set req.http.x-redir = "https://" + req.http.host + req.url;
return(synth(850, "Moved permanently"));
}
}
sub vcl_synth {
if (resp.status == 850) {
set resp.http.Location = req.http.x-redir;
set resp.status = 302;
return (deliver);
}
}
sub vcl_recv {
if ( req.http.host == "example.com" || req.http.host == "www.example.com" ) {
call redirect_to_https;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment