Rewrite to preserve query for local file

I’m trying to serve local copies of websites downloaded from the Wayback When Machine. Files were downloaded using the wayback_machine_downloader tool, and as a side effect are saved to disk as their original URL’s, including the query strings.

Typically it looks like this:


I’ve been trying different incantations of rewrite to get this to work, but I simply can’t. Currently I’m stuck on this:

log stdout
errors stdout
tls off
rewrite {
  # r .*
  to {uri} {path}?{query} {path}

It simply will not serve up one of those files, it just returns a 404.

Any advice, or even just advice on how to get caddy to give more verbose logs to help inspect what is actually going on?

I dont think you will be able to create a rewrite directive to manage this as there is too much “exception” to the standard of how a webserver works.

However it would be resonably trival to write a php script that served the file from disk. Your caddy file could redirect to a index.php page which would then load the file from disk based on the path and query strings.

rewrite {
 to {path} {path}/  /index.php

a php file like this would do the trick


echo   file_get_contents($_SERVER['REQUEST_URI'] . '?' . $_SERVER['QUERY_STRING'];

This is untested, but something like this should work well.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.