Caddy V2: php issue due to missing rewrite?

Hi all,

Please find below description of issue i’ve have due to incorrect/missing rewrite.

1. Caddy version (caddy version):

v2.0.0 h1:pQSaIJGFluFvu8KDGDODV8u4/QRED/OPyIR+MWYYse8=

2. How I run Caddy:

a. System environment:

Raspberry 3b+ with Raspbian + VNCServer + Syncthing + Minidlna + 2 Sata HDD + Caddy 2.0 + Gogs.

b. Command:

Caddy is start with :
caddy start -config=/home/pi/.config/caddy/Caddyfile

c. Service/unit/compose file:

d. Caddyfile:

File CaddyFile

localhost {
    root * /media/data_sata2/www
    php_fastcgi unix//run/php/php7.3-fpm.sock
    encode zstd gzip
    file_server browse
    tls internal
    log {
        #output file /var/log/caddy.log
    #Added for Php
    #rewrite match:indexFiles {path}/ # No redirect required

    # internally rewrite directory URIs to index.php files
    try_files {path} {path}/ /index.php/{uri} # Last part is the problem

    # proxy any requests for PHP files to backend via FastCGI
    #matcher phpFiles {
    #    path *.php

3. The problem I’m having:

On localhost root, i have 2 files:
index.html which is a static page with links to different path (directories)
With Firefox
if i type
i see correct page.

if i type
i see correct page.

index.php contains only: <?php phpinfo(); ?>

If i type
localhost/[my path] /index.php which is index.php for Wordpress
It seems i’m rerouted to localhost/index.php !
I’ve same render and not the index.php (Wordpress index.php).

If i type
localhost/[my path] /park.php which contains static HTML page
It seems i’m rerouted to localhost/index.php !
I’ve same render and not the index.php (Wordpress index.php).

4. Error messages and/or full log output:

i’ve got no error except on all paths i go. I see the root index.php file and not the correct index.php i’ve in my path.

5. What I already tried:

i typed on browser localhost/[my path] /park.php which contains static HTML page and my browser shows me index.php render.
it seems that all path i set, i get localhost/index.php ! as i’m always redirected to localhost root.

What is correct rewrite needed to no be redirected to localhost/index.php ? because it seems to be that.
I didn’t able to look for solution.
I tested what is in this :

without success.

Thanks for your help?



I went ahead and edited the Caddyfile in your post to fix the formatting, it was very hard to read. FYI, to embed code blocks in your posts, use ``` on lines before and after the code. Don’t use > as that’s for quotes, not code.

What does this mean exactly? You omitted the “my path”, so I don’t understand the question. Are you putting non-Wordpress PHP files in there that you’re trying to serve as well? What does the directory structure look like? You can use the tree command from the webroot to show a text representation of the directory structure (feel free to remove the extra files that aren’t relevant from the output).

Take a look at the expanded form of php_fastcgi:

You’ll notice that it has its own try_files logic there that should already do what you need, so you don’t need to specify your own.


Hi Francis,
thanks for formatting my wrong message.
I’ll try to take time before tonight to test with fast_phhcpi other options.


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