That’s not a valid matcher, you want path_regexp. See the file matcher syntax here, path_regexp is not an option of file, but instead its own matcher.
One of the problems are that the order in which matchers are executed is not guaranteed, so trying to use the regexp result in the same named matcher can’t be relied upon.
Here’s a related thread for I think the same app as you’re using, but unfortunately that user never got to a working solution.
My best suggestion would be something like this (also you don’t need to copy and modify the php_fastcgi expanded form, the rewrite below will happen beforehand and it should be fine to use php_fastcgi as-is):
This will make sure that the path_regexp matcher happens first, then in a subroute, will invoke the try_files directive (different than the try_files matcher, it’s essentially a shortcut, see the docs) to rewrite the path.
Thank you, but the “rule” for forum/ is not working fine, I will explain whats different with that path below.
I have now this one kind of working:
file_server
@a {
path_regexp a ^/(forum/|cms/|calendar/|filebase/|blog/|gallery/)?([a-zA-Z0-9-/]+)$
}
rewrite @a /{http.regexp.a.1}index.php?{http.regexp.a.2}&{query}
The only thing left is, that /forum or /forum/ is not working, but everything below does, like /forum/foo.
The special thing on /forum is, that it is a real folder with an index.php inside. So somethign is not working there.
(I’m using the short php_fastcgi syntax again)
Yeah, just noticed he had the same issue as I did…
The separate rule is working fine and now it looks like everything is running as it should.
Thank you very much!
As requested my Caddyfile:
That’s great! I replied in the other thread, so hopefully they can take from your example
Btw, a couple comments. In Caddy v2.1 (beta 1 is already out if you want to try it), we have multiple syntax improvements that can simplify your config.
Also, you’re using the log directive incorrectly; in Caddy v2.0, it would silently ignore the arguments on the same line, the syntax for log is different in v2 than v1. In v2.1, we throw a parse error with the syntax you used.