Follow the guide How can I redirect one domain to another domain using an Application Load Balancer?
Highlight steps:
Listeners - Add rule - Add condition
- Choose Redirect to.
- Specify the protocol and port, as required by your use case.
- Change Original host, path, query to Custom host, path, query.
- For Host, enter example2.com.
- For Path and Query, keep the default values (unless your use case requires you to change them).
- Set the Response to HTTP 301 "Permanently moved" or HTTP 302 "Found".
Redirect to https://example2.com:443/#{path}?#{query}
Status code: HTTP_301
Note
The only difference between 307 and 302 is that 307 guarantees that the method and the body will not be changed when the redirected request is made. With 302, some old clients were incorrectly changing the method to GET: the behavior with non-GET methods and 302 is then unpredictable on the Web, whereas the behavior with 307 is predictable. For GET requests, their behavior is identical. More details, please check [307 Temporary Redirect - HTTP | MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/307)
Use the 301 code only as a response for GET or HEAD methods and use the 308 Permanent Redirect for POST methods instead, as the method change is explicitly prohibited with this status. More details, please check [301 status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/301)
- Global regions: Lambda@edge
- China regions: DO NOT configure redirection on ALB, handle the redirect and 307 status code on Lambda or Nngix as target group of ALB
Client -> ALB -> Lambda -> Orginal Server
Client -> ALB -> Nginx -> Orginal Server