13

I'm trying to setup a Wordpress website with multisite:

  • example.com

  • example.com/fr

With the following Caddyfile:

example.com:80 {
    redir https://www.example.com{uri}
}

www.example.com:80 {
    root /app/public
    gzip

    fastcgi / 127.0.0.1:9000 {
        ext .php
        split .php
        index index.php
    }

    rewrite {
        regexp ^/[_0-9a-zA-Z-]+(/wp-.*)
        to {path} {path}/ {1}
    }

    rewrite {
        regexp ^/[_0-9a-zA-Z-]+(/.*\.php)$
        to {path} {path}/ {1}
    }

    rewrite {
        if {path} not_match ^\/wp-admin
        to {path} {path}/ /index.php?_url={uri}
    }

    log stdout
    startup /usr/sbin/php-fpm7.0 -F -O &
}

When I reach /fr/wp-admin/, I get a 301 to /wp-admin/.

Does anybody know how to fix that ?

Samber
  • 153
  • 1
  • 8

2 Answers2

1

This caddy config works for me. Hope this helps.

rewrite {
    regexp ^(/[^/]+)?(/wp-.*)
    to {2}
}

rewrite {
    regexp ^(/[^/]+)?(/.*\.php)
    to {2}
}

rewrite {
    if {path} not_match ^\/wp-admin
    to {path} {path}/ /index.php?{query}
}
user1949536
  • 574
  • 5
  • 6
0

This is what you indicated with:

rewrite {
    regexp ^/[_0-9a-zA-Z-]+(/wp-.*)
    to {path} {path}/ {1}
}

Which in your case, with the request /fr/wp-admin/ will try to serve:

  1. {path} = /fr/wp-admin/

  2. {path}/ = /fr/wp-admin/

  3. {1} = /wp-admin/, which is the first block captured in your parenthesis

Meaning Caddy doesn't find the admin under /fr, or isn't redirected property afterward, depending on what you aim.

Adrien Leravat
  • 2,731
  • 18
  • 32