Reputation: 603
I have an EC2 instance on AWS which has route53 hosted zone.I have used AWS Certificate Manager for SSL and then used Classic Load balancer for the same to achieve https redirection.
I have simple website running on that instance and have apache server installed with it. Also I have made .htaccess file for redirection.
It works on following cases:
1] example.com -> https://www.example.com
2] https://www.example.com -> https://www.example.com
3] http://www.example.com -> https://www.example.com
It should also work on the following case but it does not
www.example.com -> https://www.example.com
I have written all the htaccess rule perfectly but when I add www redirection rule the load balancer status goes OutService.When I remove that rule it works perfectly.
Working .htaccess for normal cases
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
When I add rule for www.example.com -> https://www.example.com
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]
Upvotes: 0
Views: 230
Reputation: 4451
It is probably because your classic ELB health check is set on HTTP and it expects 200 okay reply from server but because of redirection rules, it's getting 302/301. One solution would be to use TCP for health check, it'll only check SYN, SYN+ACK, however, the more robust solution is to use Application load balancer, you can choose your own success Health check Status code (2xx,3xx) and you don't need redirection rule on backend, ALB provides redirection rules which you can use for all of above purpose.
Upvotes: 2