Reputation: 3864
I'm looking for an answer on how to rewrite an AWS S3 URL on my website, using Apache mod_proxy
.
Here's the rule I'm using in my .htaccess file on my website :
<IfModule mod_proxy.c>
RewriteEngine On
RewriteRule ^img_test/([a-z-]+)-([0-9]+)\.png$ https://[MY-BUCKET].s3.eu-west-3.amazonaws.com/[MY-BUCKET-SUBFOLDER]/img/c/$2.png [P]
</IfModule>
On my AWS S3 Bucket, I''ve set all "Block public access" settings to Off, and implemented the following bucket policy :
{
"Version": "2012-10-17",
"Id": "S3_Policy",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::[MY-BUCKET]/*"
}
]
}
As well as the following CORS rule :
{
"AllowedHeaders": [
"*"
],
"AllowedMethods": [
"GET",
"PUT",
"POST",
"DELETE"
],
"AllowedOrigins": [
"https://www.my-website.com"
],
"ExposeHeaders": []
}
]
However, when I call the following URL : https://www.my-website.com/img_test/test-5.png
, I'm getting a 403 Forbidden error, instead of getting the contents of the file located on my AWS S3 bucket.
If I use the same .htaccess rule, but without the [P]
flag, the URL redirects to https://[MY-BUCKET].s3.eu-west-3.amazonaws.com/[MY-BUCKET-SUBFOLDER]/img/c/5.png
.
I suspect there might be something more to configure on my AWS S3 bucket, but I'm at a loss to figure out exactly what.
Upvotes: 0
Views: 19