Apache - retrieve file from S3 if it does not exist on disk

Published: 2018-03-02 15:37:39 +0000
Categories: Misc,




On hosted systems with limited disk space, you might occasionally want to archive files out to Amazon S3 (or some other filer). This would usually result in URLs changing, though, so the ideal situation would be to have Apache simply proxy the request through to your filer if it cannot find the file on disk

This snippet checks for the file within the document root and if it does not exist, sends a request our to an S3 bucket


SSLProxyEngine On

RewriteEngine On
RewriteRule ^/(.*)$ https://s3.[amazonregion].amazonaws.com/[yourbucketname]/$1 [P,QSA,L]

Usage Example

SSLProxyEngine On

RewriteEngine On
RewriteRule ^/(.*)$ https://s3.eu-west-3.amazonaws.com/examplebucket/$1 [P,QSA,L]


  • mod_rewrite
  • mod_ssl
  • mod_proxy


apache, proxy, conditional proxy, Amazon S3, filer,

Latest Posts

Urldecode string (LUA)
FFMPEG Convert YUV444p to YUV420p (BASH)
Forcing FFMPEG to honour segment length in HLS Stream Creator (BASH)
Force CURL to place request to a specific IP (BASH)
Set a variable only if it is undefined (Javascript)
Ignore query string with Nginx caching proxy (NGinx)
Get breakdown of UK and non-UK votes for a Parliamentary Petition (Python)
Decompress Mozilla Firefox jsonlz4 bookmark backup files (Python)
Setting Git author details for a single repo (Git)
Checking Virtual Machine Resource Allocations with Libvirt (BASH)

Copyright © 2019 Ben Tasker | Sitemap | Privacy Policy
Available at snippets.bentasker.co.uk and snippets.6zdgh5a5e6zpchdz.onion