When on my local environment, I want to serve the media files of my dev site from the live version.
With Apache, this was done like so :
<code><IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^testsite.local$
RewriteRule ^wp-content/uploads/(.*)$ https://prodsite.org/wp-content/uploads/$1 [NC,L]
</IfModule>
</code>
<code><IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^testsite.local$
RewriteRule ^wp-content/uploads/(.*)$ https://prodsite.org/wp-content/uploads/$1 [NC,L]
</IfModule>
</code>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^testsite.local$
RewriteRule ^wp-content/uploads/(.*)$ https://prodsite.org/wp-content/uploads/$1 [NC,L]
</IfModule>
So, when the URL contains /uploads/
, the domain should be changed from devsite.local
to prodsite.org
.
For example :
https://testsite.local/wp-content/uploads/logo.webp
becomes
https://prodsite.org/wp-content/uploads/logo.webp
How can this be done with Caddy ?