# Purge based on URL

**URL:** <https://community.fastly.com/t/purge-based-on-url/2912>\
**Category:** General\
**Created:** [September 25, 2024, 6:41pm UTC](https://community.fastly.com/t/purge-based-on-url/2912 "2024-09-25T18:41:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sdarwin](https://sea1.discourse-cdn.com/flex019/user_avatar/community.fastly.com/sdarwin/32/309_2.png) [@sdarwin](https://community.fastly.com/u/sdarwin)\
**Post date:** [September 25, 2024, 6:41pm UTC](https://community.fastly.com/t/purge-based-on-url/2912/1 "2024-09-25T18:41:49Z")

</div>

Hi,

Here is an example scenario.

Let’s say the path you are searching for includes “my\_path\_segment” and the surrogate key will be called “my\_surrogate\_key”.

1. Create a VCL snippet to select the right pages:

Name: “Set Surrogate-Key”  
Type: fetch  
Priority: 99  
Code:

```auto
if ( req.url ~ "^.*/my_path_segment/.*$" ) { 
   set beresp.http.surrogate-key = if (beresp.http.surrogate-key, beresp.http.surrogate-key + " " + "my_surrogate_key", "my_surrogate_key"); 
}

```

An advantage of priority 99 instead of 100 is so it will be evaluated before 100 which may include `return (deliver);` statements that short-circuit evaluation.

Run curl locally.

```auto
$ curl -X POST -H 'Fastly-Soft-Purge:1' -H 'Fastly-Key: YOUR_FASTLY_TOKEN' -H 'Accept: application/json' https://api.fastly.com/service/<SID>/purge/<S-Key>

```

An issue I encountered when researching this topic was the `curl` command was missing on many doc pages when searching for “Fastly Purge”, “Purge based on URL”, and “Surrogate Key”. I eventually found it in a page about “Soft Purges”.

However, when someone is investigating “fastly purge”, the concept of “soft” is not at the top of your mind. The admins might consider propagating the `curl` commands to a few more of the existing documentation pages even those which aren’t focused specifically on “soft purge”.

Any comments are welcome about the above steps.

---

<div class="post-metadata">

**Author:** ![aspires](https://sea1.discourse-cdn.com/flex019/user_avatar/community.fastly.com/aspires/32/464_2.png) [@aspires](https://community.fastly.com/u/aspires)\
**Post date:** [September 25, 2024, 8:48pm UTC](https://community.fastly.com/t/purge-based-on-url/2912/2 "2024-09-25T20:48:21Z")

</div>

That’s good feedback on the prominence of Soft Purge in the docs. Are there specific ones you checked early on / are there specific docs where you’d expect to see different content?

---

<div class="post-metadata">

**Author:** ![sdarwin](https://sea1.discourse-cdn.com/flex019/user_avatar/community.fastly.com/sdarwin/32/309_2.png) [@sdarwin](https://community.fastly.com/u/sdarwin)\
**Post date:** [September 25, 2024, 9:43pm UTC](https://community.fastly.com/t/purge-based-on-url/2912/3 "2024-09-25T21:43:40Z")

</div>

Hi Austin,

The information can eventually be found. It’s not entirely missing.

Let’s say the goal is to find the `curl` command in conjunction with a surrogate key. That’s necessary to purge based on a wildcard URL path. If it shows “curl -X PURGE”, that’s not quite it yet.

google this search, without quotes: “fastly purge surrogate key”  
result 1: [Purging with surrogate keys](https://docs.fastly.com/en/guides/purging-with-surrogate-keys) NO  
result 2: [Working with surrogate keys](https://docs.fastly.com/en/guides/working-with-surrogate-keys) NO  
result 3: [Purging | Fastly Documentation](https://www.fastly.com/documentation/reference/api/purging/) Initially, NO. Ctrl-F (find `curl` on page), no result. But it is there! hidden away. You have to click to find it.  
result 4: [Purging | Fastly Documentation](https://www.fastly.com/documentation/guides/concepts/edge-state/cache/purging/) NO  
result 5: [Surrogate-Key | Fastly Documentation](https://www.fastly.com/documentation/reference/http/http-headers/Surrogate-Key/) NO  
result 6: [fastly purge | Fastly Documentation](https://www.fastly.com/documentation/reference/cli/purge/) NO  
result 7: [https://support.globaldots.com/hc/en-us/articles/360019893392-Fastly-how-to-Purge-by-Surrogate-Key](https://support.globaldots.com/hc/en-us/articles/360019893392-Fastly-how-to-Purge-by-Surrogate-Key) NO Some clues though.  
result 8: [Purging | Fastly Help Guides](https://docs.fastly.com/en/guides/purging) NO  
result 9: [Cache Invalidation on Fastly with Surrogate Keys](https://www.hward.com/varnish-cache-invalidation-with-fastly-surrogate-keys/) NO  
result 10: [Use surrogate key purges for purge-all and single URL purge | Fastly Documentation](https://www.fastly.com/documentation/solutions/examples/use-surrogate-key-purges-for-purge-all-and-single-url-purge/) NO

Google this search, without quotes: “fastly purge based on url”.

result 1: [Purging | Fastly Help Guides](https://docs.fastly.com/en/guides/purging) NO. But it leads to:  
result 1a: [Authenticating URL purge requests via API](https://docs.fastly.com/en/guides/authenticating-api-purge-requests) NO  
result 1b: [Purging a URL via the web interface](https://docs.fastly.com/en/guides/purging-a-url) NO  
result 1c: [Purging all content via the web interface](https://docs.fastly.com/en/guides/purging-all-content) NO  
result 1d: [Purging with surrogate keys](https://docs.fastly.com/en/guides/purging-with-surrogate-keys) NO  
result 1e: [Soft purges](https://docs.fastly.com/en/guides/soft-purges) YES. That is where I found it. (But I didn’t want “soft” purge, so that threw me off).  
result 1f: [Working with surrogate keys](https://docs.fastly.com/en/guides/working-with-surrogate-keys) NO  
result 2: [Purging a URL via the web interface](https://docs.fastly.com/en/guides/purging-a-url) NO.  
result 3: [Purging | Fastly Documentation](https://www.fastly.com/documentation/reference/api/purging/) Initially, NO. Ctrl-F (find `curl` on page), no result. But it is there! hidden away. You have to click to find it.  
result 4: [Purging | Fastly Documentation](https://www.fastly.com/documentation/guides/concepts/edge-state/cache/purging/) NO  
result 5: [Purge everything under a URL path prefix | Fastly Documentation](https://www.fastly.com/documentation/solutions/examples/purge-everything-under-a-url-path-prefix/) NO  
result 6: [bash - Purge a URL from the Fastly CDN via API call with curl or wget - Stack Overflow](https://stackoverflow.com/questions/28502789/purge-a-url-from-the-fastly-cdn-via-api-call-with-curl-or-wget) NO  
result 7: [Soft purges](https://docs.fastly.com/en/guides/soft-purges) YES, this is where I found it.  
result 8: [PURGE all for given resource](https://community.fastly.com/t/purge-all-for-given-resource/2904) NO  
result 9: [https://www.drupal.org/project/fastly/issues/3438700](https://www.drupal.org/project/fastly/issues/3438700) NO  
result 10: [caching - Fastly purges pages for no reason - Stack Overflow](https://stackoverflow.com/questions/69786948/fastly-purges-pages-for-no-reason) NO

---

<div class="post-metadata">

**Author:** ![sdarwin](https://sea1.discourse-cdn.com/flex019/user_avatar/community.fastly.com/sdarwin/32/309_2.png) [@sdarwin](https://community.fastly.com/u/sdarwin)\
**Post date:** [September 25, 2024, 11:22pm UTC](https://community.fastly.com/t/purge-based-on-url/2912/4 "2024-09-25T23:22:34Z")

</div>

If there is any discovery here, it might be:

- [Purging | Fastly Documentation](https://www.fastly.com/documentation/reference/api/purging/) is the page which is meant to show the answer of this query.
- While being maximally elegant and beautiful, the page may be outsmarting casual users, such as myself.

I wonder if there could be a compromise between displaying all data in that page, and having everything hidden inside drop-down sections that don’t allow Ctrl-F find-on-page. At least worth thinking about.

Going further…

search: ctrl-f find on page trigger expand

[javascript - Expanding hidden content when stepping with search on page (ctrl+f) in chrome - Stack Overflow](https://stackoverflow.com/questions/53043662/expanding-hidden-content-when-stepping-with-search-on-page-ctrlf-in-chrome)  
[javascript - How to expand all rows of a html table on Ctrl+F - Stack Overflow](https://stackoverflow.com/questions/22830204/how-to-expand-all-rows-of-a-html-table-on-ctrlf)  
[javascript - Expand all collapsible sections for text search - Stack Overflow](https://stackoverflow.com/questions/44267536/expand-all-collapsible-sections-for-text-search)  
[javascript - Detect page find/search to expand a collapsible - Stack Overflow](https://stackoverflow.com/questions/41001165/detect-page-find-search-to-expand-a-collapsible?noredirect=1&lq=1)  
( only a few and not necessarily the correct ones. there are more solutions out there )

---

<div class="post-metadata">

**Author:** ![aspires](https://sea1.discourse-cdn.com/flex019/user_avatar/community.fastly.com/aspires/32/464_2.png) [@aspires](https://community.fastly.com/u/aspires)\
**Post date:** [September 27, 2024, 5:27pm UTC](https://community.fastly.com/t/purge-based-on-url/2912/5 "2024-09-27T17:27:25Z")

</div>

This is good feedback, I’ll pass this on to the team. Thanks!
