I have a Tomcat 8 app deployed on Elastic Beanstalk which uses a sub-domain of my main app. Both are separate applications and do not interact. I have a mod_rewrite
rule to redirect all http
requests to https
in a configuration file in the .ebextensions
folder -
files:
"/etc/httpd/conf.d/httpd_redirect.conf" :
mode: "000644"
owner: root
group: root
content: |
LoadModule rewrite_module modules/mod_rewrite.so
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://sub.domain.com%{REQUEST_URI} [L,R]
So ideally, someone accessing the app at sub.domain.com
or http://sub.domain.com
will be redirected to https://sub.domain.com
.
The problem is that this works only after I request the app with https
first. So, I have to request https://sub.domain.com
first, and from then onwards, non-https
requests will be redirected to https
.
Also, this only works until I clear my browser cache. Once the cache is cleared, non-https
requests are no longer redirected to https
. I have make an https
request first again for the redirection to start working.
What could be causing this? The main domain uses a separate certificate from that of the sub-domain if it matters.
How can I force the application to always use https
?
I have a secure listener enabled on the load balancer with this configuration file in .ebextensions
-
option_settings:
aws:elb:listener:443:
SSLCertificateId: arn:aws:acm:us-east-2:1234567890123:certificate/####################################
ListenerProtocol: HTTPS
InstancePort: 80