How to redirect or change all incoming urls with file extension(aspx) to html using S3 redirection rule or Cloudfront

0

Hi, i want to know if it's possible and how to redirect or change all incoming urls with file extension(aspx) to html using S3 redirection rule or Cloudfront. i tried to used keyprefix but it's not working. i also add "HttpErrorCodeReturnedEquals": "404" to the following json instruction but did not work [ { "Condition": { "KeyPrefixEquals": (wildcard for anything before).aspx" }, "Redirect": { "ReplaceKeyWith": "(wildcard for anything before).html" } } ] the website is in statict s3 bucket

2 Answers
0
Accepted Answer

S3 redirect only can change prefix which is basically the folder name. The prefix does not contain the file name. So, the way you want to do this is not supported.

The only other option you really have is to upload a zero-byte file with the .aspx extension that you want redirected to html. You will have to do this for every .html page you have. With that you can change the System Metadata to perform a 301 redirect to any other object.

So, say you have a page named /products/myproducts.html you would upload a zero-byte file named /products/myproducts.aspx (Note: It really does not have to be zero byte any content will work) In the meta data key of x-amz-website-redirect-location you will place /products/myproducts.html

Here are the examples on how to do the various rewrite rules if you need additional information.

With CloudFront you might be able to rewrite using lambda edge, but I don't think that would be easy or cost effective.

If your front end is actually a single page application using something angular or react you can do client-side routing and do this in the browser.

profile picture
answered a year ago
0

i will do the redirection on the client side that was one of the option i was thinking to use. thank for the answer

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions