Apache2 RewriteRule: Map images folder from remote system to your local virtual host

Submitted by Peter Majmesku on Mon, 08/29/2016 - 20:33

With the following directive in your Apache2 virtual host file (at /etc/apache2/sites-available) you must not download the images from products etc. on your local system for development. You just map your local folder location to the remote one. The following example is for a Drupal site (files are under /sites/default/files):

RewriteEngine On
RewriteOptions Inherit
RewriteRule /sites/default/files/(.*)\.(jpeg|jpg|gif|png)$ http://www.my-website.com/sites/default/files/$1.$2 [L,R=301]


This 1 line does also work:

RedirectMatch ^/media/(.*)\.(jpeg|jpg|gif|png)$ https://www.my-website.com/static/media/$1.$2

This setting can be also made in the .htaccess file in your project folder. It's important that this setting is made in theĀ <IfModule mod_rewrite.c> section.


Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
CAPTCHA This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.