While the config you gave (including the regex) could be translated literally to a Caddyfile, regex checking is completely unnecessary for something this simple - so this would be the best way to do it:
The regex is unnecessary. Your working example is functionally identical to the following:
rewrite {
to /index.php?q={uri}
}
Your working example, however, doesn’t approximate if (!-e $request_filename). To achieve that in Caddy, we add the files on disk as paths to check first: {path} {path}/ index.php?q={uri}.
I’m not sure what your PHP application expects to receive from your query; it might be sensitive to the leading slash?
{uri} resolves to the entire resource, including anchors and queries, e.g. /path/to/file.jpg#anchor?query=value.
{path} is just the first part, e.g. /path/to/file.jpg.
{file} is just the filename, e.g. file.jpg.
Check out the placeholder docs for the full list; you can frequently retrieve the information you want without resorting to regex at all, which is a win for performance.
I figured out that there {query} should be used, but i can’t make {path} {path}/ work correctly, it’s not serving static files on my website, like /assets/theme/main/js/bootstrap.js
The rewrite will combine the web root (set by the root directive) with the requested path into an absolute filepath and then test that location on disk.
For example, for a given root /var/www/html, and a given request /assets/theme/main/js/bootstrap.js, a rewrite to {path} will check for the existence of /var/www/html/assets/theme/main/js/bootstrap.js on the host disk, and serve that if it exists.
I’ve merged your latest post into this thread to keep the conversation on this topic in one place.
As noted above, the literal translation of your Apache example to a Caddyfile is as follows:
rewrite {
regexp ^/(.*)$
to {path} {path}/ /index.php?q={1}
}
If it’s not working as expected, you should look into logging to determine what’s going wrong. Your full Caddyfile and a file tree of your web root might also be helpful to troubleshoot.
Just to confirm - if you comment out import friendlyurls, reload Caddy, and run curl -I http://my-host.com:2015/assets/theme/main/js/bootstrap-switch.js, does it work again?