Conditionally changing a URL
Last updated 2018-08-01
To conditionally change a URL based on the domain, include VCL that looks something like this:
1
2
3
if (req.http.host ~ "^restricted") {
set req.url = "/sanitized" req.url;
}
If you have shielding enabled, however, add the following code instead to avoid rewriting the URL twice:
1
2
3
if (req.http.host ~ "^restricted" && req.url !~ "^/sanitized") {
set req.url = "/sanitized" req.url;
}
In Fastly's web interface, this VCL would be the equivalent of creating a new Header:
and then creating a request condition that restricts connections to that host: