I am using an AWS Elastic Load Balancer, and have set up the following rule to convert http
traffic to https
.
/etc/httpd/conf.d/httpd_redirect.conf
<VirtualHost *:80>
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTP_USER_AGENT} !^ELB-HealthChecker
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
</VirtualHost>
However, when I access my website via its domain (www.thewhozoo.com), I can see the protocol is http
and not https
.
Any ideas why the rewrite rule is not working?
Thanks
More info
/etc/httpd/conf/httpd.conf
...
Include conf.d/*.conf
Include conf.d/elasticbeanstalk/*.conf
...
The above is created on deployment by:
.ebextensions/myapp.config
container_commands:
01_setup_apache:
command: "cp .ebextensions/enable_mod_deflate.conf /etc/httpd/conf.d/enable_mod_deflate.conf"
files:
"/etc/httpd/conf.d/httpd_redirect.conf" :
mode: "000644"
owner: root
group: root
content: |
<VirtualHost *:80>
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTP_USER_AGENT} !^ELB-HealthChecker
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
</VirtualHost>
ELB Listeners
Best Answer
You have a configuration snippet
/etc/httpd/conf.d/ssl_rewrite.conf
Typically such snippets get loaded by an
Include
orIncludeOptional
directiveor
from your main
httpd.conf
.The problem is that those snippets only apply to your main configuration and don't apply to any
VirtualHost
sections...Either include those settings in the virtual host definition, or load that snippet there:
Or even better, don't use mod_rewrite and set: