Rewriterule for WP multisite uploads file


I run a Multisite WP website with Caddy.

Images are physically located under the blogs.dir folder, in numbered folders from that correlating to each site’s blog-id#.

With Apache, these locations are rewritten via the .htaccess file and served up to the “new” location:

# uploaded files
RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]

Does anyone now how to translate this Apache rewrite rule in a Caddyfile?

Thanks for your help.

You can use the rewrite directive to do something similar. Without testing it would be something like this

rewrite {
    regexp  (.*)/files/(.*)
to wp-includes/ms-files.php?file={2}

Could wholesale copy the existing regex to be honest, e.g.:

rewrite {
  r ^([_0-9a-zA-Z-]+/)?files/(.+)
  to wp-includes/ms-files.php?file={2}

Other than formatting the config in a rewrite block, the only modification required should be changing the capture group in the target from $2 to {2}, per the rewrite placeholder:

  • destinations… is one or more space-separated paths to rewrite to, with support for request placeholders as well as numbered regular expression captures such as {1}, {2}, etc.

Thanks both of you for your help, I will give your example a try.

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