Woocommerce in Subdir RestAPI Problem with Caddy

1. The problem I’m having:

I run 2.6.2-5 on Debian 12 and php8.2-fpm with Wordpress latest + Woocommerce 8.5.0. Nearly everything runs fine, except the restAPI calls of the cart and checkout page makes problems. Unsure if it is my fault or a bug, but I would like to stay with Caddy not being forced to Apache if possible. I have 10+ hours searching with it and now I run out of ideas. Any hint to make the cart working would be greatly appreciated. Thank you.

This was opened Woocommerce in Subdir RestAPI Problem with Caddy · Issue #6034 · caddyserver/caddy · GitHub but I was redirected here.

2. Error messages and/or full log output:

Setup:

/var/www/svc.example.com-SSL/somdir/ → here is wordpress

Caddyfile:

svc.example.com:443 {
    root * /var/www/svc.example.com-SSL

    php_fastcgi localhost:9000 {
        root /var/www/svc.example.com-SSL
    }

    file_server
    encode zstd gzip

    log {
        output file /var/log/caddy/svc.example.com-SSL.access.log {
            roll_size 30MB
            roll_keep 5
            roll_keep_for 240h
        }
    }

    # Prevent access to dot-files, except .well-known
    @dotFiles {
      path */.*
      not path /.well-known/*
    }

    @blockedext {
        path *.orig *.patch *README *.txt *.git *.md *.dist *.yml *.conf *.json *Dockerfile /protected/
    }
    respond @blockedext 404

    @static {
        file
        path *.ico *.css *.js *.gif *.jpg *.jpeg *.png *.svg *.woff *.pdf *.webp
    }
    header @static Cache-Control max-age=5184000

    tls hostmaster@example.com  {
        protocols tls1.2 tls1.3
    }

    ##############################################################
    # Wordpress on /somedir
    ##############################################################

    @disallowed {
        path *xmlrpc.php
        path *.sql
        path /somedir/wp-content/uploads/*.php
    }
    respond @disallowed 404

    @wccart {
      path  /wc/store/v1/cart
    }
    redir @wccart /somedir/index.php/wp-json/wc/store/v1/cart?{query}

    @wcbatch {
      path  /wc/store/v1/batch
    }
    redir @wcbatch /somedir/index.php/wp-json/wc/store/v1/batch?{query}

    @wc {
      path  not /wc/store/v1/batch
      path  not /wc/store/v1/batch
      path  /wc/*
      path  wc/*
    }
    redir @wc /somedir/index.php/wp-json/{uri}?{query}
}

I already redirect /wc (unsure why this is called wrong from the woocommerce side in this setup) and from this changes on the cart call worked. and th v1 json also included batch, but responds with 404.

2024-01-11 15:03:07|null|/wc/store/v1/batch?_locale=user|POST|HTTP/2.0|302|Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:113.0) Gecko/20010101 Firefox/113.0
2024-01-11 15:03:08|null|/somedir/index.php/wp-json/wc/store/v1/batch?_locale=user|GET|HTTP/2.0|404|Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:113.0) Gecko/20010101 Firefox/113.0
2024-01-11 15:02:54|null|/wc/store/v1/cart?_locale=user|GET|HTTP/2.0|302|Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:113.0) Gecko/20010101 Firefox/113.0
2024-01-11 15:02:55|null|/somedir/index.php/wp-json/wc/store/v1/cart?_locale=user|GET|HTTP/2.0|200|Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:113.0) Gecko/20010101 Firefox/113.0

here is a copy of https://svc.example.com/wc/store/v1 which is correct redirected and includes the batch endpoint as it looks like:

the forum does not let me post > 30K so i refer to
Woocommerce in Subdir RestAPI Problem with Caddy · Issue #6034 · caddyserver/caddy · GitHub for the json list

NOTE: doman and subdir is replaced by search & replace. it was m y d o m a i n, but got an error not letting me post. so i replaced again with example.

3. Caddy version:

I run 2.6.2-5 on Debian 12 and php8.2-fpm with Wordpress latest + Woocommerce 8.5.0.

4. How I installed and ran Caddy:

see above

a. System environment:

Debian 12, MariaDB, Systemd, no Docker

That’s an old version. You’re probably using the caddy package in Debian community repos. That does not get updated by us.

Please instead use our official apt repo:

You don’t need to repeat root here, it’s redundant, since you’re already using the root directive above. You can remove it here.

You’re not doing anything with this matcher (it’s not applied to any directive) so it does nothing.

Don’t specify protocols, there’s no benefit. In fact, this would prevent Caddy from enabling TLS 1.4 if such a thing ever exists in the future. Let Caddy use secure defaults.

These can be simplified, you can inline the matcher since it’s a simple path matcher.

    redir /wc/store/v1/cart /somedir/index.php/wp-json/wc/store/v1/cart?{query}
    redir /wc/store/v1/batch /somedir/index.php/wp-json/wc/store/v1/batch?{query}

I don’t know WooCommerce, so I can’t help with that. You’ll need to dig into why its rules are triggering a 404.

Couldn’t you run it in a subdomain instead of a subpath, like woo.example.com or whatever? It would probably be much simpler. Running things in subpaths adds a lot of complexity, most apps need to be aware of being inside a subpath and need to be configured as such with a “base path” config of somekind to work correctly.

Thank you for your reply. I installed the latest version, but no changes. Will install Apache now to see its related to Caddy or related to Wordpress/Woocommerce.

Apache reacts same, so bug must be in woocommerce. Will search further and switch back to Caddy.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.