Wordpress caddyfile with mutiple subdomains - cannot remove "index.php" from URL

1. CONFIGURATION

Caddy version 2 , Installed on CentOS v7, used to serve multpile wordpress sites/installations (each in a webroot subdir), Wordpress v5.6.2

2 GOAL

Remove the “/index.php/” string from URLs , possibly using the standard “custom permalink setup” in each Wordpress admin dashboard.

3 CURRENT SOLUTION

With the attache Caddyfile, the /index.php/ string is removed from the root served web only, but NOT from the inner websites.

Caddy documentation is not clear about using caddyfile when multiple sites are served, and I did not find a similar case on this forum, so I need your help.

4 CURRENT CADDYFILE

mysite.com , www.mysite.com {
    tls /etc/certificates/chain.pem /etc/certificates/key.pem
    root * /var/www/wordpress
    php_fastcgi 127.0.0.1:9000
    file_server
    encode gzip

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

mysite.com/innerweb , www.mysite.com/innerweb {
    tls /etc/certificates/chain.pem /etc/certificates/key.pem
    root * /var/www/wordpress/innerweb
    php_fastcgi 127.0.0.1:9000
    file_server
    encode gzip

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

I tried using the URI and REWRITE Directive, with no success - I’m not expert in Regex, and probably missing the correct syntax and behind-the-scenes caddyfile interpretation by the caddy server

#uri replace /innerweb/ /innerweb/index.php/
#rewrite not path /innerweb/wp-admin /innerweb/* /innerweb/index.php/
#rewrite /innerweb/* /innerweb/index.php?{query}
#rewrite /innerweb/index.php/* /innerweb/index.php?{query}
#uri replace /innereb/index.php/ /innerweb/index.php?{query}

5 Resources:

https://denbeke.be/blog/servers/caddy-server-and-wordpress-php-fpm/

I would be very grateful for any help and hint, thank you

Leo

In Caddy v2, path mathing is exact, so this site only matches if the path is exactly /innerweb, but not /innerweb/foo.

Generally, I discourage using paths in site labels, because it makes matching confusing to read. Instead, you should do that path matching inside of your other site block. It removes redundancy.

Serving PHP sites in subpaths is sorta tricky right now due to the defaults that php_fastcgi uses unfortunately.

What I would recommend doing is serving your “inner” site on a separate subdomain instead, like innerweb.mysite.com.

1 Like

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