Redirect non-www to www with AWS Elastic Beanstalk – Application Load Balancer
AWS elastic beanstalk can be considered the fastest way to deploy any application (in my case it was Laravel) running on AWS. You can choose Apache or Nginx as webserver and many RDS available right within elastic beanstalk. A separate RDS can also be configured and attached to Elastic Beanstalk environment. Load balancer configured with elastic beanstalk will be application based (Application Load Balancer). The subject line (redirect non-www to www with aws elastic beanstalk) will be achieved by configuring application load balancer.
AWS elastic beanstalk is a one stop shop which can provide you an easy way to deploy your web application within no time. A simple easy to follow dashboard for everything (application server, load balancer, RDS and other required rules) can be added from elastic beanstalk dashboard.
An overview of AWS elastic beanstalk is given in below pictures.
Solution!
non-www to www redirection rule will be configured on application load balancer. Follow under listed instructions:
- Go to your Load Balancer from AWS console
- Select your Load Balancer
- go to LISTENERS tab
- Click under Rules -> view/edit rules
- Add another rule
- Condition -> Host Header: windowstechupdates.com
- Add Action -> Redirect to:
- HTTPS -> #{port} – its mandatory
- CUSTOM HOST, PATH, QUERY
- Host: www.windowstechupdates.com
- leave everything as it is and 301-Perman
save the listener rules and test the website to make sure that domainname.com is redirecting to www.domainname.com.
on a side note: To get a static public IP address for your application either you need to configure global accelerator or network load balancer. Network load balancer is available for every zone as compared to global accelerator which might not be available in every region (as an example, Frankfurt). I have already created a post on network load balancer to get a static IP address which is available at this URL.