0

In the question htaccess redirect to https://www the answer was basically this:

RewriteEngine On

RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.

RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
# [NC] is a case-insensitive match
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

The second higest upvoted answer stated that if you only have a single certificeted domain that one should reverese the order.

In my case I only have a SSL certificate for https://www.example.com but not for https://example.com. I am using the above .htaccess settings, so I have not reversed the order.

When I enter http://example.com I expected it to be redirected first to https://example.com (because of the L flag) and to throw a warning like

enter image description here

To my surprise, this gets correctly redirected to https://www.example.com.

Why is this not redirected to https://example.com and throwing a warning?

Adam
  • 25,960
  • 22
  • 158
  • 247
  • 1
    @anubhava I deleted browser cache, tried it with another browser that I never used and in inkognito mode. They all redirected as above. – Adam Sep 02 '18 at 10:47
  • @anubhava okay I checked **caching disabled** and the first request is `http://example.com` with status `301`. Next there is the `https://www.example.com` request with status `200`. There is neither a `http://www.example.com` nor a `https://example.com` request. – Adam Sep 02 '18 at 11:51
  • I suspect there is some other rule/code doing a redirect from `http://example.com` to `https://www.example.com` in your system – anubhava Sep 03 '18 at 10:04

0 Answers0