How can I redirect one domain to another domain using an Application Load Balancer?
I want to redirect one domain to another domain using an Application Load Balancer.
"I want to redirect one domain to another domain using an Application Load Balancer.Short descriptionThe Application Load Balancer service supports redirection of domain names as well as redirection from HTTP to HTTPS. If you have a domain that points to an Application Load Balancer, then it's a best practice to configure redirection using the Application Load Balancer rather than Amazon Simple Storage Service (Amazon S3).ResolutionNote: If you receive errors when running AWS Command Line Interface (AWS CLI) commands, make sure that you’re using the most recent AWS CLI version.If you're using an Application Load Balancer as part of your configuration, you can use it to redirect one domain to another:Open the Amazon Elastic Compute Cloud (Amazon EC2) console.On the navigation pane, choose Load Balancers under Load Balancing.Select your load balancer, and then choose Listeners.Choose View/edit rules for the load balancer listener that you want to use.Choose the Add rule icon (the plus sign).Choose Insert Rule.Choose Add condition.In the conditions section (IF), choose Add condition.Choose Host header, and then enter your hostname (for example, example.com).To save, choose the checkmark icon.In the actions section (THEN), choose Add action.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".To save, choose the checkmark icon.The THEN section now appears:Redirect to https://example2.com:443/#{path}?#{query}Status code: HTTP_301Choose Save.Note: If both domains point to the same Application Load Balancer, be sure that you:Have separate certificates for both domains, ORUse a Subject Alternative Name (SAN) certificate to validate the domainsTo confirm that the redirect is working:1.    In the AWS CLI, use the curl function.curl    -Iv https://example1.com -L* Rebuilt URL to: https://example1.com/. . . * Connected to example1.com (1.2.3.4) port 443 (#0)<SSL handshake> > Host: example1.com.   ———> Host name is example1.com > User-Agent: curl/7.61.1>    Accept: */*> * Connection state changed (MAX_CONCURRENT_STREAMS == 128)!< HTTP/2 301       ———> ALB does redirection < server: awselb/2.0< date: Fri, 06 Mar 2020 09:18:33 GMT< content-type: text/html< content-length: 150    < location: https://example2.com:443/.   ——> redirected to “example2.com” < * Issue another request to this URL: 'https://example2.com:443/‘. ———> Curl initiates another request that is to example2.com *   Trying 34.195.219.169...    * TCP_NODELAY set<SSL handshake> > Host: example2.com.   ———> Host name has changed to example2.com > User-Agent: curl/7.61.1> Accept: */*> * Connection state changed (MAX_CONCURRENT_STREAMS == 128)!<    HTTP/2 200 ——> We got a response2.    In your internet browser, enter example1.com and confirm that it redirects to example2.com.Note: Application Load Balancer supports only 301 and 302 redirects. These redirects allow the client to change the HTTP method from POST to GET in subsequent requests. If a 307 redirect is needed, then the redirect must come through the target application.Related informationHow do I redirect an apex domain to its subdomain or any other domain using S3 and Route 53?Application load balancers now support multiple TLS certificates with smart selection using SNIFollow"