We've been making changes to how we organize and display our docs. Our work isn't done but we'd love your feedback.
Getting started
Basics
Domains & Origins
Performance

Configuration
Basics
Conditions
Dictionaries
Domains & Origins
Request settings
Cache settings
Headers
Responses
Performance
Custom VCL
Image optimization
Video

Security
Access Control Lists
Monitoring and testing
Securing communications
TLS
Web Application Firewall

Integrations
Logging endpoints
Non-Fastly services

Diagnostics
Streaming logs
Debugging techniques
Common errors

Account info
Account management
Billing
User access and control

Reference

    Conditionally changing a URL

      Last updated August 01, 2018

    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:

    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

    Back to Top