Nginx rewrite rules translation to Caddy v2

Hi everyone,

I’m looking to run a multisite for WordPress Bedrock. It requires 2 specific rewrite rules.
https://roots.io/docs/bedrock/master/server-configuration/#nginx-configuration-for-bedrock

specifically:

rewrite ^/(wp-.*.php)$ /wp/$1 last;
rewrite ^/(wp-(content|admin|includes).*) /wp/$1 last;

I’m not sure how to translate that in the Caddy way :slight_smile:

my current, working, caddyfile is very simple and adapted from the Wiki for local development:

# the following config works for a single WP bedrock site on localhost
{
  debug
}
http:// {
  root * /var/www/html/web
  php_fastcgi wordpress:9000 {
    root /var/www/html/web
  }
  file_server

}

Thank you!

Not sure if this works, but you might want to try.

uri path_regexp ^/(wp-.*.php)$ /wp/$1 
uri path_regexp ^/(wp-(content|admin|includes).*) /wp/$1 

The second root inside of php_fastcgi is redundant. You can remove it and the braces.

You probably want the path_regexp matcher, paired with the rewrite handler:

@multisiteFirst path_regexp first ^/(wp-.*.php)$
rewrite @multisiteFirst /wp/{re.first.1}

@multisiteSecond path_regexp second ^/(wp-(content|admin|includes).*)
rewrite @multisiteSecond /wp/{re.second.1}
2 Likes

Thank you!

Maybe it’d be useful to add the config for it in the wiki as well, if people like me are looking to switch from nginx to caddy.

Thanks again!

Feel free to write a wiki for it. I don’t use Wordpress so I wouldn’t be the right person to do it.

Or, get Bedrock to include Caddy in their docs.

1 Like