Documentation

Configuration for Caddy Web Server server

If you are using a Caddy Web Server that does not support .htaccess rules, additional configuration is required for the Xilifox Image Optimizer plugin to work properly.

  • Step 1. #

    Start an SSH connection to your website or forward this instruction to your server administrator.

  • Step 2. #

    Go to the host configuration directory using the command:

    cd /etc/caddy

    Use the command to edit the configuration file:

    nano Caddyfile

  • Step 3. #

    In the configuration file, find the block responsible for your domain and add the following rules in it:

    # BEGIN XIO
    header /wp-content/*/*.jpg Cache-Control "private"
    header /wp-content/*/*.jpeg Cache-Control "private"
    header /wp-content/*/*.png Cache-Control "private"
    header /wp-content/*/*.webp Cache-Control "private"
     
    @acceptsAvif {
        header Accept *image/avif*
        path_regexp avif ^/wp-content/(.+)/(.+)\.(jpg|jpeg|png|webp)$
    }
    @acceptsWebp {
        header Accept *image/webp*
        path_regexp webp ^/wp-content/(.+)/(.+)\.(jpg|jpeg|png)$
    }
     
    handle @acceptsAvif {
        @hasAvif file /wp-content/uploads-xio/{re.avif.1}/{re.avif.2}.{re.avif.3}.avif
        rewrite @hasAvif /wp-content/uploads-xio/{re.avif.1}/{re.avif.2}.{re.avif.3}.avif
    }
    handle @acceptsWebp {
        @hasWebp file /wp-content/uploads-xio/{re.webp.1}/{re.webp.2}.{re.webp.3}.webp
        rewrite @hasWebp /wp-content/uploads-xio/{re.webp.1}/{re.webp.2}.{re.webp.3}.webp
    }
    # END XIO

    Please remember to:

    • add rules in the block responsible for your domain
    • if you have several blocks responsible for your domain (e.g. separate for HTTP and HTTPS), add rules in all blocks
    • add these rules before other directives in the block

  • Step 4. #

    Restart the Caddy server using the command:

    service caddy restart

  • Step 5. #

    That’s all! Our plugin will work properly.

    If you encounter any problems, please, contact us. We will try to help you.

Not the solution you are looking for?

Please check other articles or open a support ticket.