Setting Surrogate-Key headers based on a URL

You can mark content with a surrogate key and use it to purge groups of specific URLs at once without purging everything, or purging each URL singularly.

Follow these instructions to set Surrogate-Key headers based on a URL:

  1. Log in to the Fastly web interface.
  2. From the All services page, select the appropriate service. You can use the search box to search by ID, name, or domain.
  3. Click the Edit configuration button and then select the option to clone the active version. The Domains page appears.
  4. Click the Content link. The Content page appears.
  5. Click the Create header button. The Create a header page appears.

    the Header page

  6. Fill out the Create a header fields as follows:
    • In the Name field, enter a human-readable name for the header. This name is displayed in the Fastly web interface.
    • From the Type menu, select Cache, and from the Action menu, select Set.
    • In the Destination field, enter http.Surrogate-Key.
    • In the Source field, enter regsub(req.url, "^/(.*)\.(.*)$", "\1"). This will accept a URL that looks like /foo.html and will create the Surrogate-Key foo.
    • From the Ignore if set menu, select No.
    • In the Priority field, enter 10.
  7. Click the Create button to create your header.
  8. Click the Activate button to deploy your configuration changes.
Back to Top