How to Exclude URL From VarnishNovember 3, 2016

 

In this KB:

  • What do Varnish Rules do
  • How to Exclude (bypass) URLs from Varnish

 

Varnish can improve website performance through caching dynamic content. Generally, e-commerce websites with secure cart pages are not set up for being cached. Through this feature, specific pages can be excluded whenever required.

Click here to find out how to exclude/include cookies in Varnish.

Step 1: Select the Target Application

Log into the Cloudways Platform with your credentials. Click on Applications in the top menu bar and select the target application from the list.

application-management

Step 2: Check if Varnish is Enabled

From the Application Settings section in the Application Management area, enable Varnish. If it is disabled from this section, Varnish settings would not be available for use.

applications-settings

Step 3: Add Varnish Rule

Before proceeding with add the Varnish rules, it is really important that you refer to the following notes:

  • Excluding from Varnish excludes the entire link from Varnish to prevent caching on it. If you exclude a link (/file.php) then that file would not cache through Varnish.
  • If you use an incomplete destination link (/checkout/) and can have several links after checkout/ such as checkout/cart or checkout/items, all links with checkout/ would not cache through Varnish.

Now Select Varnish Settings. Then, click Add New Rule.

varnish-settings-add-new-rule-cookie-include

Choose URL from the Type drop-down menu that you wish to exclude. Enter your string in the Value input field. In this example, all links using /checkout/ will be excluded from Varnish and would not cache content.

Note: Only relative URLs can be excluded from caching (eg: /checkout/) and not absolute URLs (http://domain.com/checkout/).

Tip: Regex can also be used.

2016-11-21_16h13_53

 

Once added, the rule will be visible in the Varnish Settings section. The rule can be edited or removed whenever needed.2016-11-21_16h14_43

Important Note:

  • You may need to use Varnish Purge if objects/URLs are previously being cached.
Have Questions? You can start a discussion on Community Forum

8 Responses

  1. Renan says:

    How to pass the cache for a dynamic URL like .. ?add-to-cart= .. ?
    Thanks in advanced.

    • Cloudways says:

      You can use these rules for excluding checkout/ and carting pages/ for all links and for dynamic links as well. However, please note, that our default vcl for Woocommerce Application is already set to exclude checkout and cart cache links. Therefore it is not necessary for you to add these again separately.

      Cloudways Team

  2. Josimar says:

    I have WordPress multisite. I work with subdomain and mapped domains. So I have the following URLs in my network. Example:

    site1.mydomain.com (sub domain)
    site2.mydomain.com (sub domain)
    site3.com (mapped domain)

    Is it possible to delete cart pages from wocoomecer for all addresses? Or will it need to be configured one by one? Can I use for example “/ checkout”? Will this work for all domains in my network?

    Abs,
    Josimar

    • Cloudways says:

      Yes you can exclude all carting pages from your multisite for each domain. You can use /checkout in your varnish settings for excluding url. Since the sites are all based on a single network all domains using checkout would be excluded from caching. This is application wide and would effect on all of its domains. If you want to use it for specific domains you can use the whole url for defining it as such.

      In case you still face any issue then please contact our support any time.

      Cloudways Team

  3. Nino says:

    Great feature, thanks. Do I have to include URLs explicitly or does Varnish cache all URLs automaticalle, which are not on the exclude list?

    • Cloudways says:

      When Varnish is enabled, it includes all pages in your site by default. There are some exceptions which we have specified in our VCL such as the Woocommerce cart pages. This feature allows you to Exclude Url’s from your applicaiton which do not require caching for any particular reason depending on your application needs.

      Cloudways Team

  4. Tim Gary says:

    This doc shows a ful URL path including the http://

    The admin area help item says that only relative urls are to be used.

    Which is correct?? One way or another, one place needs an update 🙂

    • Cloudways says:

      Thank you for highlighting this. We have now updated our article. You would be using the relative URL to define the URL’s that need to be excluded from varnish.

      Cloudways Team

Still need help? Our support team is waiting to help you. Ask them now