Get wp-content/uploads files from live site on localhost

While modifying clients WordPress sites I don’t download the uploads directory contents so to avoid 404s in Chrome’s Developer Tools console I modified .htaccess to redirect those URLs to the live site. Tested in a docker container.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_NAME} localhost
RewriteRule ^wp-content/uploads/(.+)$ http://www.example.com/wp-content/uploads/$1 [R=301,L]
</IfModule>

view raw
htaccess
hosted with ❤ by GitHub

Redirect images (other media) content to live production site

During some redesign projects it’s handy to have the images (other media) rendered, but sometimes it could be a struggle to download from specific paths.

For WordPress sites I use the following htaccess rule:

RedirectMatch 301 /wp-content/uploads/(.*)$ http://www.example.com/wp-content/uploads/$1

Than for other, custom stuff:
RedirectMatch 301 /media/(.*)$ http://www.example.com/media/$1