Answers.Body: <p>Excluded URI patterns apply to the URI only and <em>not</em> to the query string. For that reason, I'd recommend changing your URI structure so that the cached blog page exists at <code>/blog</code>, whereas uncached search pages exist at <code>/blog/search</code>. That way you can exclude the latter from being cached and achieve your desired result, either by using a query string such as <code>/blog/search?query=something</code> or by setting up a <a href="https://craftcms.com/docs/4.x/routing.html#dynamic-routes" rel="nofollow noreferrer">route</a> such as <code>/blog/search/*</code> which will allow a URI of <code>/blog/search/something</code> to work.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-11-27T12:10:44.903Z
Answers.Text: Thanks Ben. That's a good workaround. I was hoping this is possible with the current setup, but your answer clarifies it's not supported.
Answers.UserDisplayName: Matanya
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-11-27T01:05:23.667Z
Answers.LastActivityDate: 2022-11-27T01:05:23.667Z
Answers.UserDisplayName: Ben Croker
Body: <p>I have a blog listing page, which I would like to cache using <a href="https://putyourlightson.com/plugins/blitz" rel="nofollow noreferrer">Blitz</a>.</p>
  <p>However, when a user searches the blog (<code>/blog?search=something</code>) I'd like to load the un-cached version.</p>
  <p>I'm using server rewrite to serve static pages, so I excluded the <code>search</code> query parameter:</p>
  <pre><code>RewriteCond %{DOCUMENT_ROOT}/cache/blitz/%{HTTP_HOST}/%{REQUEST_URI}/index.html -s
  RewriteCond %{REQUEST_METHOD} GET
  RewriteCond %{QUERY_STRING} !(^token|^search|^success)= [NC]
  RewriteRule .* /cache/blitz/%{HTTP_HOST}/%{REQUEST_URI}/index.html [L]
  </code></pre>
  <p>I then tried excluding the page using a regular expression (<code>.+?search=</code>) in the <a href="https://putyourlightson.com/plugins/blitz#included-excluded-uri-patterns" rel="nofollow noreferrer">exclude URIs</a> section.
  However, it seems to only support exclusion by the base URL, without the query parameters.</p>
  <p>Next I tried to set an exclusion on the <a href="https://putyourlightson.com/plugins/blitz#advanced-settings" rel="nofollow noreferrer">Advanced Settings</a> tab, where my selected option is &quot;Cache URLs with query strings as the same page&quot;. However, this did not have an effect and the page was still cached when the <code>?search</code> query was present. The documentation on this option says:</p>
  <blockquote>
  <p>The query string parameters to include or exclude when determining if
  and how a page should be cached (regular expressions may be used).</p>
  </blockquote>
  <p>Which is somewhat cryptic to my understanding. I assume it serves to minimize the number of unique versions when the &quot;Cache URLs with query strings as unique pages&quot; is selected, but I'm not sure how it works when &quot;Cache URLs with query strings as the same page&quot; is selected.</p>
  <p>Is there an obvious way to achieve this that does not entail excluding the &quot;bare&quot; version of the blog as well?</p>
  
Tags: <cache><plugin-blitz>
Title: Blitz: Exclude URL with specific query parameters
ThreadText: # Blitz: Exclude URL with specific query parameters
  
  (Asked by: username_0 on 2022-11-20)
  
  I have a blog listing page, which I would like to cache using [Blitz](https://putyourlightson.com/plugins/blitz).
  
  However, when a user searches the blog (`/blog?search=something`) I'd like to load the un-cached version.
  
  I'm using server rewrite to serve static pages, so I excluded the `search` query parameter:
  
  ```
  RewriteCond %{DOCUMENT_ROOT}/cache/blitz/%{HTTP_HOST}/%{REQUEST_URI}/index.html -s
  RewriteCond %{REQUEST_METHOD} GET
  RewriteCond %{QUERY_STRING} !(^token|^search|^success)= [NC]
  RewriteRule .* /cache/blitz/%{HTTP_HOST}/%{REQUEST_URI}/index.html [L]
  
  ```
  
  I then tried excluding the page using a regular expression (`.+?search=`) in the [exclude URIs](https://putyourlightson.com/plugins/blitz#included-excluded-uri-patterns) section.
  However, it seems to only support exclusion by the base URL, without the query parameters.
  
  Next I tried to set an exclusion on the [Advanced Settings](https://putyourlightson.com/plugins/blitz#advanced-settings) tab, where my selected option is "Cache URLs with query strings as the same page". However, this did not have an effect and the page was still cached when the `?search` query was present. The documentation on this option says:
  
  > The query string parameters to include or exclude when determining if
  > and how a page should be cached (regular expressions may be used).
  
  Which is somewhat cryptic to my understanding. I assume it serves to minimize the number of unique versions when the "Cache URLs with query strings as unique pages" is selected, but I'm not sure how it works when "Cache URLs with query strings as the same page" is selected.
  
  Is there an obvious way to achieve this that does not entail excluding the "bare" version of the blog as well?
  
  **Tags:** cache, plugin-blitz
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-11-27. Score: 1 | Accepted answer
  
  Excluded URI patterns apply to the URI only and *not* to the query string. For that reason, I'd recommend changing your URI structure so that the cached blog page exists at `/blog`, whereas uncached search pages exist at `/blog/search`. That way you can exclude the latter from being cached and achieve your desired result, either by using a query string such as `/blog/search?query=something` or by setting up a [route](https://craftcms.com/docs/4.x/routing.html#dynamic-routes) such as `/blog/search/*` which will allow a URI of `/blog/search/something` to work.
  
  > **Comments:**
  > **username_0**: Thanks Ben. That's a good workaround. I was hoping this is possible with the current setup, but your answer clarifies it's not supported.  
  
  ---
  
  