0

I am attempting to make my local host and staging environments a bit prettier by failing over to production if an image is not found locally. I can get proxy pass to work and always forward requests to our production environment, but I am not sure how to make the virtual host check locally, then conditionally forward to production on a 404.

<VirtualHost *:80>
    ServerName media.localhost
    ServerAlias media.localhost
    DocumentRoot /var/www/media-server/
    SSLProxyEngine on
    ProxyPass / https://media.production.com/
</VirtualHost>

Alternatively I am not sure if proxy pass is even the best approach here? Maybe a mod_rewrite is better?

Edit: Additional context, image paths are stored relative to domain in the database, with the images stored in the file system. So when pulling in production data there are lots of broken images when developing locally.

1
0

Using mod_rewrite:

RewriteCond /var/www/media-server/%{REQUEST_URI} -f
RewriteRule - [L]

RewriteRule "/(.*)$" https://media.production.com/$1 [P,QSA]

Be sure to consider the warnings for P

Edit: I may have given you enough rope to hang yourself: you may be facilitating a dev DOSing your production resource. Crazy things happen during development. You may wish to point them at a non-production resource.

1
  • I did this ErrorDocument 404 https://media.production.com%{REQUEST_URI} and it seems to work. – cnizzardini Feb 6 '19 at 0:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.