WordPress: How to use live images on localhost?

Wordpress: How to use live images on localhost?

In this article, I’ll explain ‘How to use live images on localhost?’ when you are working on WordPress site locally. Sometimes you don’t have much time/space to download the huge files on the local system. And without these files, your site designs may glitch. To clone your site locally please installed the latest database of the live site on your local system.

Use live images on localhost

The best way to do it, is to use URL Rewrites via .htaccess.


What is a .htaccess file?

.htaccess is a configuration file used to alter the default behavior of an Apache web server software. Most common usage is to redirect the HTTP request to some URLs based on some conditions. For example, we can hide the .html or .php extensions of the URLs to make it SEO friendly

Before moving ahead, you need to make sure mod_rewrite apache module is loaded and overridable from .htaccess. Open “.htaccess” file in your project’s root folder.

Access server images locally

In above rule .htaccess will tell the browser that all files under “uploads” directory have been permanently moved to a new location i.e. http://siteurl.com/wp-content/uploads/ in our example. Because we have passed R=301 condition at the end online so this is “301 Permanently Redirect”.  Change “livesiteurl.com” with your domain name to serve images from your live server.

If you want redirection will only work on your localhost & only if the file doesn’t exist locally. Then you may add the following condition before above-mentioned rule:

So new condition rule set will be:

So here is the full .htaccess code for normal WordPress site.

Source: My GitHub Account

Leave a Reply