How to append a folder to a URL resource

1. Caddy version (caddy version):

2.4.3

2. How I run Caddy:

Installed via PPA and it runs automatically via systemd or manually from caddy start

a. System environment:

Ubuntu 20.04

b. Command:

caddy start

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:

https://thedeveloper.club {
        tls email@gmail.com
        encode zstd gzip
        root * /var/www/
        php_fastcgi localhost:9000
        # Refer to the Caddy docs for more information:
        # https://caddyserver.com/docs/caddyfile
        file_server
        try_files * /public/index.php
        @cachedFiles {
          path *.ico *.css *.js *.gif *.jpg *.jpeg *.png *.svg *.woff
        }
        header @cachedFiles Cache-Control max-age=5184000

3. The problem I’m having:

This is based on the question ask at How to assume index.php without sbowing it in the url which worked great, but this would be the follow up:

  1. When someone visits the site they do not see the index.php in the URL, which is good, but this same index.php is part of Laravel, so when it goes to another folder, the resource urls break. The reason behind this is that they are trying to look for the resource inside /public but they are getting / instead. So for example, the URL the resources get would be this:

https://site.com/plugins/bootstrap/dist/css/bootstrap.min.css

Which visually is what we want, but the ACTUAL resource is in

https://site.com/public/plugins/bootstrap/dist/css/bootstrap.min.css

Dont know if this makes sense, since it was a bit difficult for me to explain the logic here.

We want to show the resource as this if possible: https://site.com/plugins/bootstrap/dist/css/bootstrap.min.css

While pulling it correctly from https://site.com/public/plugins/bootstrap/dist/css/bootstrap.min.css

which has appended as a prefix the folder /public

Any idea, guidelines?

4. Error messages and/or full log output:

5. What I already tried:

6. Links to relevant resources:

If you’re using Laravel, then you must set your root to /var/www/public. It’s a security issue. You don’t want users to be able to access files outside of public, because that’s the source code for your site, and may contain secrets.

1 Like

If you’re francislavoie, then you must let me kiss you. I was just grabbing this project from another team and was focusing more on the structure of Laravel than the actual caddyfile. When you see me, slap me.

1 Like

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