Redirect non-www to www with AWS Elastic Beanstalk

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.

non-www to www redirection

non-www to www redirection


non-www to www redirection rule will be configured on application load balancer. Follow under listed instructions:

  1. Go to your Load Balancer from AWS console
  2. Select your Load Balancer
  3. go to LISTENERS tab

non-www to www redirection

  1. Click under Rules -> view/edit rules
  2. Add another rulenon-www to www redirection
  • Condition -> Host Header:
  • Add Action -> Redirect to:
  • HTTPS -> #{port} – its mandatory
  • Host:
  • leave everything as it is and 301-Perman

save the listener rules and test the website to make sure that is redirecting to

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.

Azhar Ali Buttar has 20 years of experience working in different domains within IT industry. From network protocols to server hardening, he knows about multiple areas and has been working side by side with MNCs to provide cost-effective security and infrastructure solutions. Azhar’s expertise lies in off-site and hybrid infrastructure deployment using multiple platforms which includes, but not limited to, Azure, AWS, Google and Private Clouds. He has also been leading several infrastructure and security teams to deploy and perform security optimization in multiple projects, and now leads Nocastra with his decision-making and client-oriented skills.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.