LOG IN SIGN UP
Documentation

Generating HTTP redirects at the edge

When users request information from your origin servers, you may want to redirect them for various reasons. For example, you may want to redirect them to either a secure or non-secure version of a web page, or to pages that have been moved or updated since the last time they were requested.

You can send these redirects from the edge rather than having to go to origin by creating a synthetic response with the appropriate redirect status code and then creating a content rule with the proper Location header.

Create a new response and condition

To generate redirects at the edge, start by creating a new response with the appropriate status code and a new condition describing when the response can be applied.

  1. Click the Content section.
  2. In the Responses area, click the New button to create a new response. The New Response window appears.

    the New Response window

  3. Fill out the fields of the New Response window as follows:

    • In the Name field type a meaningful name for your response (e.g., Redirect to blog).
    • From the Status menu, select the HTTP status code that should be included in the header of the response (e.g., 301 Moved Permanently or 302 Moved Temporarily for redirections).
    • Leave the MIME Type field blank.
  4. Click Create to create the new response.

  5. Click the gear icon to the right of the new response you just created and select Request Conditions from the menu. The Choose Condition window appears.

  6. In the Options section, click the New button. The New Condition window appears.

    the New Condition window

  7. Fill out the fields of the New Condition window as follows:

    • In the Name field type a meaningful name for your condition (e.g., URL is /wordpress).
    • In the Apply If field, type the logical expression to execute in VCL to determine if the condition resolves as True or False (e.g., req.url ~ "^/wordpress").
    • Leave the Priority set to 10.
  8. Click Create to create the new condition.

Create a new header and condition

Complete the creation of a synthetic redirect by creating a new header and condition that modifies that response by adding the location header based on the status code and the matching URL. This ensures the redirect only applies when both of those are true.

  1. In the Headers area, click the New button to create a new header. The New Header window appears.
  2. Fill out the fields of the New Header window as follows:
    • In the Name field type a meaningful name for your header (e.g., Location for wordpress redirect).
    • From the Type and Action menus, select Response and Set respectively.
    • In the Destination field type http.location.
    • In the Source field, type the source location of the new content (e.g., "http://www.my-site.com/new-location/of/item").
    • Leave the Ignore If Set and Priority fields at their default settings.
  3. Click Create to create the new header.
  4. Click the gear icon to the right of the new header you just created and select Response Conditions from the menu. The Choose Condition window appears.
  5. In the Options section, click the New button. The New Condition window appears.
  6. Fill out the fields of the New Condition window as follows:
    • In the Name field type a meaningful name for your condition (e.g., Set location for blog redirect).
    • In the Apply If field, type the logical expression to execute in VCL to determine if the condition resolves as True or False (e.g., req.url ~ "^/wordpress" && resp.status == 301). The resp.status needs to match the response code generated in the response above.
    • Leave the Priority set to 10.
  7. Click Create to create the new condition.

Translations available [JA] 日本語