Skip to content

Instantly share code, notes, and snippets.

@noelboss
Last active May 22, 2020
Embed
What would you like to do?
Serve files from server when not available on your local machine
# Get all wp-content files from remote if localy not available (Perfect for local development environment
# Determine environment
# Local
SetEnvIf Server_Addr ^\:\:1 WPENV=local
SetEnvIf Server_Addr ^127\.0\.0\.1 WPENV=local
SetEnvIf Host ^(www\.)?local\. WPENV=local
# Release
SetEnvIf Host ^(www\.)?dev\. WPENV=release
SetEnvIf Host ^(www\.)?release\. WPENV=release
<IfModule mod_rewrite.c>
RewriteEngine On
# Rewrite only non existing files
RewriteCond %{REQUEST_FILENAME} !-f [NC]
# only when local or on release system
RewriteCond %{ENV:WPENV} ^(local|release)$
# only when in uploads folder
RewriteCond %{REQUEST_URI} ^/wp-content/uploads/
# add your domain:
RewriteRule ^(.*)$ https://www.your-domain.com/$1 [L]
</IfModule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment