Let’s say I have an object at http://mybucket.s3.amazonaws.com/folder1/folder2/pdf/something.pdf
There are NO other files in the bucket as this was setup for a legacy link that is being used in an old marketing campaign.
I want that link to redirect to https://example.com
(the screenshot has a different domain but SO won’t let me post it here).
Tried to setup static hosting with variations of this but can’t seem to get this to work. Is there a way to do a redirect for this one file?
In the interim I had to add a blank pdf that just has a link for the user to click which isn’t ideal.
2
Answers
The other option seems to be "Redirect requests for an object". Instructions are in the official documentation.
https://docs.aws.amazon.com/AmazonS3/latest/userguide/how-to-page-redirect.html
I think this guide will work for you.
Basically it replaces the obsolete file with an HTML file, while retaining the old name
something.pdf
. The HTML contains meta header<meta http-equiv="Refresh" content="0; URL=http://www.example.com/target/">
that should force an instant redirect to the desired location. Make sure to edit the file metadata ContentType totext/html
so that the browser is able to read it.I tried this myself as well, it works!