Last active
December 25, 2015 17:39
-
-
Save ncserny/7014367 to your computer and use it in GitHub Desktop.
Varnish: Easily redirect "olddomain.com/..." to "newdomain.com/..." URLs at the cache level.
This file contains hidden or 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
# Redirect "olddomain.com/..." to "newdomain.com/..." URLs at the cache level. | |
# Just set an error code (in our case 750) in vcl_recv when accessing old urls, then define the redirect in vcl_error. | |
# Tested with Varnish 3.X | |
sub vcl_recv { | |
# Set error code when accessing an old url. | |
if (req.http.host ~ "^(www\.)?olddomain\.com$") { | |
error 750; | |
} | |
} | |
sub vcl_error { | |
if (obj.status == 750) { | |
set obj.http.Location = "http://www.newdomain.com" + req.url; | |
set obj.status = 302; | |
return(deliver); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment