NGINX
Serve all assets:
location ~ ^(/wp-content/themes|/wp-content/uploads)/.*\.(jpe?g|gif|css|png|js|ico|pdf|m4a|mov|mp3|webm|mp4)$ {
rewrite ^ https://mydomain.com$request_uri?
permanent;
access_log off;
}
Serve 404 assets:
location ~* \.(jpe?g|gif|css|png|js|ico|pdf|m4a|mov|mp3|webm|mp4)$ {
expires 24h;
log_not_found off;
try_files $uri $uri/ @production;
}
location @production {
resolver 8.8.8.8;
proxy_pass https://mydomain.com/$uri;
}
APACHE
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.*/(uploads/.*)$ http://mydomain.com/wp-content/$1 [L,R=301,NC]