I am using elasticbeanstalk to redirect HTTP requests to a secure port.
I want to redirect all my requests to https://example.com
.
The following scenarios are working
http://www.example.com
-->https://example.com
http://example.com
-->https://example.com
However,
https://www.example.com
--> doesn't work and it redirects tohttps://www.example.com
I am using the following Rewrite rules
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
I took the help of the following article to understand the use case https://simonecarletti.com/blog/2016/08/redirect-domain-http-https-www-apache/
As per my understanding, the following condition should work
RewriteCond %{HTTP_HOST} ^www\. [NC]