Rewriterule for WP multisite uploads file

(Gilles) #1


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.

(Toby Allen) #2

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}

(Matthew Fay) #3

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.

(Gilles) #4

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