How to assume index.php without sbowing it in the url

1. Caddy version (caddy version):

2.4.2

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:
<!-- If using Docker/systemd/Kubernetes/make etc. -->

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 emai@gmail.com
encode zstd gzip
root * /var/www/
@cachedFiles {
path *.jpg *.jpeg *.png *.gif *.ico *.js *.css *.html *.svg *.ttf *.webp *.woff2 *.woff
}
try_files {path} {path}/index.php
file_server
header @cachedFiles Cache-Control “public, max-age=604800, must-revalidate”
php_fastcgi localhost:9000
}


### 3. The problem I'm having:
<!-- What are you trying to do, and what isn't working? Please describe the issue thoroughly enough so that anyone can reproduce the exact behavior you're seeing. Be as specific as possible. DO NOT USE WEB BROWSERS; use "curl -v" instead. -->

Lets say I want to show example.com/subfolder but without it saying index.php and telling caddy to assume there will always be an index.php file there. So

example.com/subfolder/index.php would turn to

example.com/subfolder

And index.php would not show in the url

Along with this. In the case index.php is not found, fallback to another specific file or files. Is this possible?

### 4. Error messages and/or full log output:
<!-- Please **DO NOT REDACT** any information except credentials. Leave domain names intact! -->
<!-- Please **DO NOT POST TRUNCATED LOG LINES** as systemd is notorious for this. -->
<!-- Please **DO NOT USE WEB BROWSERS.** Use curl -v instead. -->
<!-- Please **DO ENABLE DEBUG MODE FIRST** by adding "debug" to the global options of your Caddyfile. -->


### 5. What I already tried:
<!-- Show us what effort you've put in to solving the problem. Be specific -- people are volunteering their time to help you! Low effort posts are not likely to get good answers! -->



### 6. Links to relevant resources:

Please fill out the help topic template. We need to know version of Caddy, and what your existing Caddyfile looks like, at minimum.

Please use markdown code blocks when posting your config, to preserve formatting and whitespace. It’s very difficult to read otherwise.

Maybe you should wait until you get to your computer rather than asking from your phone.

Done. Please check it out now.

Formatting is still broken. Make sure that every ``` has a matching pair to close the code formatting block (on their own lines).

I’m unclear on what isn’t working. Does https://example.com/subfolder already work, or not?

If not, what behaviour are you seeing instead? Use curl -v to show what happens. Enable the debug global option and show us what Caddy logs. See this page in the docs for how to view your logs

No, eveything is working fine. Just want to know if the following is possible:

To go to http://example.com/subfolder and see the page without having to type http://example.com/subfolder/index.php

For example a couple of developers use phpmyadmin and when they go to the folder example.com/pma then it does not show phpmyadmin, but if they go here example.com/pma/index.php it works, so I was looking for a way to not have to type index.php and also in the case the index.php is not there, a fallback so another file could be read instead.

This line is meant to do that.

In that case, turn on debug mode, and see what Caddy is doing with rewrites on that request.

1 Like

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