Migrate v1 to v2 config / Sendy PHP

1. Caddy version (caddy version):

v2.4.6

2. How I run Caddy:

Service

a. System environment:

Ubuntu

b. Command:

Paste command here.

c. Service/unit/compose file:

Paste full file contents here.
Make sure backticks stay on their own lines,
and the post looks nice in the preview pane.

d. My complete Caddyfile or JSON config:

sendy.example.org {
     root * /var/www/sendy
     tls foo@example.org
 
     php_fastcgi /run/php/php7.0-fpm.sock {
         split .php
         index index.php
     }
  try_files {path} {path}.php
  @catch {
    path_regexp ^/([a-zA-Z0-9-]+)$
  }
  rewrite @catch {path}.php
  #rewrite ^/w/([a-zA-Z0-9/]+)$ w.php?i={query}
  #rewrite ^/l/([a-zA-Z0-9/]+)$ l.php?i={query}
  #rewrite ^/t/([a-zA-Z0-9/]+)$ t.php?i={query}
  #rewrite ^/unsubscribe/(.*)$ unsubscribe.php?i={query}
  #rewrite ^/subscribe/(.*)$ subscribe.php?i={query}
}

V1 config:

sendy.example.org {
     root /var/www/sendy
     tls foo@example.org
 
     # PHP-FPM Configuration for Caddy
     fastcgi / /run/php/php7.0-fpm.sock php {
         ext .php
         split .php
         index index.php
     }

rewrite {
    r ^/([a-zA-Z0-9-]+)$
    to {1}.php
}
rewrite {
    r ^/w/([a-zA-Z0-9/]+)$
    to w.php?i={1}
}
rewrite {
    r ^/l/([a-zA-Z0-9/]+)$
    to l.php?i={1}
}
rewrite {
    r ^/t/([a-zA-Z0-9/]+)$
    to t.php?i={1}
}
rewrite {
    r ^/unsubscribe/(.*)$
    to unsubscribe.php?i={1}
}
rewrite {
   r ^/subscribe/(.*)$
   to subscribe.php?i={1}
} 
}

3. The problem I’m having:

Not able to migrate from v1 to v2 config for Sendy PHP rewrites. I’m a bit confused by the documentation and don’t find any example for Sendy or other similar PHP applications.

4. Error messages and/or full log output:

5. What I already tried:

6. Links to relevant resources:

Please make sure to use proper post formatting, it difficult to read your post because your configs didn’t use code blocks.

Sorry. Updated.

1 Like

You probably don’t need this @catch matcher because the try_files will do the same thing for you.

But for the rest of your commented out matchers, you’ll need to use named matchers. See the docs for how the syntax looks for request matchers:

So for example, you’ll probably need to write them like this:

@w path_regexp w ^/w/([a-zA-Z0-9/]+)$
rewrite @w /w.php?i={re.w.1}

Notice that the name w is given to the path_regexp matcher, which then lets you grab the capture groups from the {re.<name>.<group>} placeholder.

1 Like

Thanks for the help. Turned out there were a few other issues that was the main cause. Mainly permissions as I had Caddy v1 running with www-data and the tutorial for Caddy v2 had its own user. I was able to get it running with these config changes :slight_smile:

2 Likes

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