Weird Caddy bug: Subdirectories not working

Hi everyone,

I have a weird Caddy Bug while using the popular PHP-MVC-Framework Symfony.

Here is my CaddyFile

censored
{
  root /srv/censored/web/

  log / stdout

  fastcgi / /run/php/php7.0-fpm.sock php {
      root /srv/censored/web
  }

  rewrite {
      to {file} /app.php?{query}
  }

  header / -Server
}

My Log

*.*.*.* - - [13/Aug/2017:21:51:07 +0200] "GET / HTTP/2.0" 200 2173
*.*.*.* - - [13/Aug/2017:21:51:07 +0200] "GET /js/ffdd5a6.js HTTP/2.0" 404 471
*.*.*.* - - [13/Aug/2017:21:51:07 +0200] "GET /css/eb44281.css HTTP/2.0" 404 471
*.*.*.* - - [13/Aug/2017:21:51:08 +0200] "GET /logo.png HTTP/2.0" 304 0
*.*.*.* - - [13/Aug/2017:21:57:07 +0200] "GET / HTTP/2.0" 200 2173
*.*.*.* - - [13/Aug/2017:21:57:07 +0200] "GET /js/ffdd5a6.js HTTP/2.0" 404 471
*.*.*.* - - [13/Aug/2017:21:57:07 +0200] "GET /css/eb44281.css HTTP/2.0" 404 471
*.*.*.* - - [13/Aug/2017:21:57:07 +0200] "GET /logo.png HTTP/2.0" 304 0

And my Tree

web
β”œβ”€β”€ app_dev.php
β”œβ”€β”€ apple-touch-icon.png
β”œβ”€β”€ app.php
β”œβ”€β”€ bundles
β”‚   β”œβ”€β”€ framework -> ../../vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Resources/public/
β”‚   └── sensiodistribution -> ../../vendor/sensio/distribution-bundle/Sensio/Bundle/DistributionBundle/Resources/public/
β”œβ”€β”€ config.php
β”œβ”€β”€ css
β”‚   β”œβ”€β”€ eb44281.css
β”‚   └── eb44281_semantic_1.css
β”œβ”€β”€ favicon.ico
β”œβ”€β”€ js
β”‚   β”œβ”€β”€ ffdd5a6_jquery_1.js
β”‚   β”œβ”€β”€ ffdd5a6.js
β”‚   └── ffdd5a6_semantic.min_2.js
β”œβ”€β”€ logo.png
β”œβ”€β”€ robots.txt
└── themes
    └── default
        └── assets
            β”œβ”€β”€ fonts
            β”‚   β”œβ”€β”€ icons.eot
            β”‚   β”œβ”€β”€ icons.otf
            β”‚   β”œβ”€β”€ icons.svg
            β”‚   β”œβ”€β”€ icons.ttf
            β”‚   β”œβ”€β”€ icons.woff
            β”‚   └── icons.woff2
            └── images
                └── flags.png

Without any reason I get 404 in the css and js directory…

I also tried:

  rewrite {
      to {path} {path}/ /app.php?{query}
  }

But that result in a 404 for the app.php…

Also im wondering, why the logo can be loaded and every other file in the web directory but not from the subdirectories (like js/ffdd5a6.js).

Thanks in advance for any help! :slight_smile:

Hi @Officiali7, welcome to the Caddy community.

I believe the {file} placeholder gives the requested filename on its own, rather than including the path to that file.

So for a request to /js/ffdd5a6.js, you are rewriting to just ffdd5a6.js. This explains why the rewrite seems to function for files within the site root, but not for files inside a folder.

That’s inconvenient, because that was going to be my next recommendation exactly, and with respect to /app.php, it’s functionally identical to the one you had previously. If Caddy can’t find the file or directory and would otherwise produce a 404, it should definitely be falling back to serving your PHP.

Can you get a request log for /app.php while using the rewrite to {path} {path}/ /app.php?{query} ?

Hey @Whitestrake!

thanks for the welcome in the Caddy Community :slight_smile:

Here is the output for to {path} {path}/ /app.php?{query}

*.*.*.* - - [14/Aug/2017:19:26:32 +0200] "GET / HTTP/2.0" 404 14 

And here for to {file} {path}/{file} /app.php?{query}

*.*.*.* - - [14/Aug/2017:19:27:00 +0200] "GET / HTTP/2.0" 404 14

I think this is realy weird :confused:

Since Caddy dont want to search in the subdirectories…

Greetz
Yannick

try using {rewrite_path} in your log to see what the url is being rewritten to to see if that gives you any further info.

1 Like

For a request to /foo/bar/file.txt, this particular placeholder combination will produce /foo/bar/file.txt/file.txt, which is probably not what you want.

{path} includes the entire path, as well as a file name if applicable, as per the request from the client.

https://caddyserver.com/docs/placeholders

1 Like

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