---
title: Custom responses that don't hit origin servers
summary: null
url: >-
  https://www.fastly.com/documentation/guides/full-site-delivery/responses/custom-responses-that-dont-hit-origin-servers
---

Fastly can send custom responses for certain requests that you don't want to hit your origin servers.

## Creating a quick response

Fastly provides features that allow you to quickly enable and configure responses for a [robots.txt file](https://www.fastly.com/documentation/guides/full-site-delivery/responses/creating-and-customizing-a-robots-file#creating-a-robotstxt-file) and [404 and 503 errors](https://www.fastly.com/documentation/guides/full-site-delivery/responses/creating-error-pages-with-custom-responses#creating-error-pages-for-404-and-503-errors). For more information, check out our guides on [creating and customizing a robots.txt file](https://www.fastly.com/documentation/guides/full-site-delivery/responses/creating-and-customizing-a-robots-file) and [creating error pages with custom responses](https://www.fastly.com/documentation/guides/full-site-delivery/responses/creating-error-pages-with-custom-responses).

## Creating an advanced response

You can create an advanced response to specify the HTTP status code, MIME type, and content of the response. For example, if you wanted to restrict caching to a URL subtree that contains images and scripts, you could configure Fastly to return an `HTTP 404 Not Found` response to requests for anything other than `/Content/*` or `/Scripts/*`. To illustrate how to implement this example, we'll show you how to create a response and corresponding request condition.

Follow these instructions to create an advance response:

1.   Log in to the [Fastly control panel](https://manage.fastly.com).

2.   From the [**Home**](https://manage.fastly.com/home) page, select the appropriate service. You can use the search box to search by ID, name, or domain.

3.   Click **Edit configuration** and then select the option to clone the active version.

4.   Click **Content**.

5. Click **Set up advanced response**.

   ![the create a synthetic response window](/img/content-responses-create-a-new-response.png)

6. Fill out the **Create a synthetic response** fields as follows:
   - In the **Name** field, enter a human-readable name for the response. For example `Return Not Found`.
   - From the **Status** menu, select an HTTP code to return to the client. For example, `404 Not Found`.
   - In the **MIME Type** field, enter the MIME type of the response. For example, `text/html`.
   - In the **Response** field, enter the plaintext or HTML content to return to the client. For example `Page not found`.

7. Click **Create** to create the response. The new response appears in the Responses area of the Content page.

   ![an example synthetic response to return when a page isn't found](/img/content-response-return-not-found.png)

### Creating the request condition

Follow these instructions to attach a request condition to the response you just created:

1. Click the **Attach a condition** link next to the response that you just created.

   ![an example add a condition window](/img/add-a-condition-return-not-found.png)

2. Click **Create a new condition**.

   ![the request conditions menu selection in the responses area](/img/return-not-found-condition.png)

3. Fill out the **Create a new condition** fields as follows:
   - From the **Type** menu, select the type of condition you want to create.
   - In the **Name** field, enter a human-readable name for the condition. For example, `Return Not Found`.
   - In the **Apply if** field, enter the request condition you want inserted into a VCL if statement. For example, `! ( req.url ~ "^/(Content|Scripts)/" )`. See below for more examples of request conditions.

4. Click **Save and apply to**. The Responses area now displays the condition that must be met in order for your response to begin being used.

   ![responses condition return not found that will trigger the display of page not found](/img/content-responses-return-not-found-condition.png)

5.   From the **Activate** menu, select **Activate on Production** to deploy your configuration changes.

## Example request conditions

Respond only if URLs don't match a certain mask, in this case `/Content/*` or `/Scripts/*`:

```vcl
! (req.url ~ "^/(Content|Scripts)/")
```

Respond only if URLs match `/secret/*` or are Microsoft Word or Excel documents (`*.doc` and `*.xls` file extensions):

```vcl
! (req.url ~ "^/secret/" || req.url ~ "\.(xls|doc)$")
```

Ignore POST and PUT HTTP requests:

```vcl
req.method == "POST" || req.method == "PUT"
```

Deny a spider or crawler using `user-agent` `"annoying_robot"`:

```vcl
req.http.user-agent ~ "annoying_robot"
```

Prevent a specific IP from connecting, in this case the IP `225.0.0.1`:

```vcl
client.ip == "225.0.0.1"
```

Use [geographic variables](https://www.fastly.com/documentation/reference/vcl/variables/geolocation/) to block traffic from a specific location (e.g., China):

```vcl
client.geo.country_code == "CN"
```

Match the `client.ip` against a CIDR range, such as `240.24.0.0/16` (this requires first creating an [ACL object in VCL](https://www.fastly.com/documentation/guides/security/access-control-lists/manually-creating-access-control-lists)):

```vcl
client.ip ~ ipRangeObject
```

## Related content

- [Response object API documentation](https://www.fastly.com/documentation/reference/api/vcl-services/response-object/)
