Redirect wordpress uploads folder to s3 bucket using .htaccess Redirect wordpress uploads folder to s3 bucket using .htaccess wordpress wordpress

Redirect wordpress uploads folder to s3 bucket using .htaccess


There are a couple of problems. You need to put the rule ABOVE your wordpress rule because wordpress rules route every request to index.php.Next you will need to use mod_proxy with the use of the [P] flag because regardless of not specifying redirect in the rewriterule, Apache will do it anyway because the substitution URL is a new domain. So Apache will perform a Redirect. So using [P] flag should proxy the content instead of doing a redirect. This should accomplish what you need.

RewriteEngine OnRewriteRule ^wp-content/uploads/(.*)$ https://BUCKET.s3.amazonaws.com/wp-content/uploads/$1 [P]# BEGIN WordPress<IfModule mod_rewrite.c>RewriteEngine OnRewriteBase /RewriteRule ^index\.php$ - [L]RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule . /index.php [L]</IfModule># END WordPress