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 application.
  2. Click the configure tab (wrench icon).

    the configure tab

  3. From the Service menu, select the appropriate service and then click the blue Configure button. The main controls for the selected service appear.

  4. Click Content from the section list on the left.

    the Content window

  5. In the Headers area at the top of the page, click the New button. The New Header window appears.

    the New Header window

  6. Fill out the New Header fields as follows:

    • In the Name field, type a human-readable name for the header.
    • From the Type menu, select Cache. From the Action menu, select Set.
    • In the Destination field, type http.Surrogate-Key.
    • In the Source field, type 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, type 10.
  7. Click the Create button to create your header.

To publish the new header, deploy the version of the service you are editing.

Back to Top