---
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 **Add advanced response**.
6. In the **Name** field, enter a human-readable name for the response. For example `Return Not Found`.
7. Click the **Attach a condition** link.
8. 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.
9. Click **Attach**.
10. Fill out the remaining **Create a response** fields as follows:
    - 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`.
11. Click **Create**.
12.   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/)
