caddy: rewrite on status code?

Would it be possible to have rewrites based on the status code? Eg. when something isn’t found, a rewrite should try to find it somewhere else. Eg. a typical .htaccess rewrite looks like this:

RewriteCond %{REQUEST_FILENAME}       !-f
RewriteCond %{REQUEST_FILENAME}       !-d
RewriteRule (.*)   index.php?id=$1  [QSA,L]

Basically, if you can’t find it on the filesystem pass it on to the main PHP script.

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 30 (3 by maintainers)

Most upvoted comments

After playing around. found a solution, Caddy already supports it!

rewrite {
    to {path} {path}/ /index.php?{query}
}
  • 1 - try path as file
  • 2 - try path as folder
  • 3 - fallback to the php parsing

Please @abiosoft help is figuring out the {path} vs {string} naming, is that fixed or it would be any other names? what other options are avaible?

But, it solves my problem, should solve @calmdev too

@hernandev

rewrite {
    ...
    /file_path /handler_path
}