Conditionally changing a URL

To conditionally change a URL based on the domain, include VCL that looks something like this:

1if (req.http.host ~ "^restricted") {
2 set req.url = "/sanitized" req.url;
3}

If you have shielding enabled, however, add the following code instead to avoid rewriting the URL twice:

1if (req.http.host ~ "^restricted" && req.url !~ "^/sanitized") {
2 set req.url = "/sanitized" req.url;
3}

In Fastly's web interface, this VCL would be the equivalent of creating a new Header:

the Header window set up to restrict a URL

and then creating a request condition that restricts connections to that host:

a New Request Condition set up to restrict a URL

Was this guide helpful?

Do not use this form to send sensitive information. If you need assistance, contact support. This form is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.