bherto39
bherto39

Reputation: 1826

How to Implement a redirect to an external url

Motivation: We're maintaining a website hosted on premises https://customerRelationsSite.com

This website will soon be gone, We would like to create a URL redirect to other sites with the following use cases

   location ~ ^/path/(?<section>.*) {
             resolver 8.8.8.8;
             proxy_pass https://othersite/newPath/$section$is$
           }

   location ~ ^/eula/prodmanager/(?<section>.*) {
             resolver 8.8.8.8;
             proxy_pass https://domain.salesforce.com/eula/prod/myapp/$section$is$
           }

Which options would you consider? or are there other optimal options available out there?

Upvotes: 0

Views: 1441

Answers (1)

wally
wally

Reputation: 3602

You can do this with a static S3 bucket:

https://docs.aws.amazon.com/AmazonS3/latest/dev/how-to-page-redirect.html

As you say, simply point (through whatever DNS means you prefer) the domain to an otherwise empty S3 bucket, and setup the redirect(s) as documented above.

For a bonus point, you can have a custom 404 page etc installed too:

 <RoutingRules>
    <RoutingRule>
    <Condition>
      <HttpErrorCodeReturnedEquals>404</HttpErrorCodeReturnedEquals>
    </Condition>
    <Redirect>
      <ReplaceKeyWith>404.html</ReplaceKeyWith>
    </Redirect>
    </RoutingRule>
  </RoutingRules>

This avoids any complexity of hosting haproxy instances or Linux instances generally - and is cost effective and recommended by AWS themselves.

(On an aside note - the 404 trick works great with Single Page Apps hosted statically in S3 buckets. Redirect all 404 URLs back to index.html - and let the SPA do the rest!)

Upvotes: 1

Related Questions