Skip to content

Instantly share code, notes, and snippets.

@tw2113
Forked from khleomix/.htaccess
Created March 6, 2025 19:04
Show Gist options
  • Save tw2113/64558a5a2969d251a1c677a9a12287fc to your computer and use it in GitHub Desktop.
Save tw2113/64558a5a2969d251a1c677a9a12287fc to your computer and use it in GitHub Desktop.
Update .htaccess to serve local uploads and fallback to prod for missing files.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# Only redirect to production if the file does not exist locally
RewriteCond %{REQUEST_URI} ^/wp-content/uploads/(.*)$
RewriteCond %{DOCUMENT_ROOT}/wp-content/uploads/%1 !-f
RewriteCond %{DOCUMENT_ROOT}/wp-content/uploads/%1 !-d
RewriteRule ^wp-content/uploads/(.*)$ https://yoursite.com/wp-content/uploads/$1 [R=301,L]
</IfModule>
# END WordPress
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment