Skip to content

Instantly share code, notes, and snippets.

@ianpegg
Last active June 20, 2022 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ianpegg/3c89a976eb94cb7e4b29f474453a87dc to your computer and use it in GitHub Desktop.
Save ianpegg/3c89a976eb94cb7e4b29f474453a87dc to your computer and use it in GitHub Desktop.
WP Uploads directory .htaccess configuration: prevent code execution and load files from LIVE when in DEV environments.
################## Uploads directory .htaccess configuration #################
## Prevent code execution and load files from LIVE when in DEV environments ##
# BEGIN Uploads directory code execution protection
<IfModule mod_php5.c>
php_flag engine 0
</IfModule>
<IfModule mod_php7.c>
php_flag engine 0
</IfModule>
<IfModule mod_php.c>
php_flag engine 0
</IfModule>
AddHandler cgi-script .php .phtml .php3 .pl .py .jsp .asp .htm .shtml .sh .cgi
Options -ExecCGI
# END Uploads directory code execution protection
# Attempt to load files from production if they're not in our local version
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) https://example.com/wp-content/uploads/$1 [NC,L]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment