Project

General

Profile

Redirect HTTP to HTTPS working in Chrome but not in IE 11

Added by cpcnw over 5 years ago

orby@raspi:~# lighttpd -v
lighttpd/1.4.45 (ssl) - a light and fast webserver
Build-Date: Jan 14 2017 21:07:19

As per snippets from https://redmine.lighttpd.net/projects/1/wiki/HowToRedirectHttpToHttps

I have the following;

$HTTP["scheme"] == "http" {
$HTTP["host"] == "mydomain.co.uk" {
     url.redirect = (".*" => "https://%0$0")
    }
}

Seems to work perfectly in latest Chrome but not in IE11

Have I missed something here?

Tia!


Replies (6)

RE: Redirect HTTP to HTTPS working in Chrome but not in IE 11 - Added by gstrauss over 5 years ago

The $HTTP["host"] line is not a regex, so %0 is not filled.
Change it to a regex $HTTP["host"] =~ "^mydomain.co.uk$" or replace the %0 in url.redirect.

$HTTP["scheme"] == "http" {
    $HTTP["host"] == "mydomain.co.uk" {
         url.redirect = (".*" => "https://mydomain.co.uk$0")
    }
}

Of course, the best recommendation is to use a more recent version of lighttpd and see the redirect example for lighttpd 1.4.50 and later on https://redmine.lighttpd.net/projects/1/wiki/HowToRedirectHttpToHttps

RE: Redirect HTTP to HTTPS working in Chrome but not in IE 11 - Added by cpcnw over 5 years ago

Hmm, neither works - its still the same :|

Should the above come after the virtual host definition for that domain?

RE: Redirect HTTP to HTTPS working in Chrome but not in IE 11 - Added by cpcnw over 5 years ago

OK this is what I have following the two vhost defs I have;

$HTTP["scheme"] == "http" {
    $HTTP["host"] =~ "^mydomain.co.uk$" {
         url.redirect = (".*" => "https://%0$0")
    }
}

But still not working in IE...

I also want to redirect non http://mydomain.co.uk to the secure https://www.mydomain.co.uk but am getting the syntax right round my neck lol!

RE: Redirect HTTP to HTTPS working in Chrome but not in IE 11 - Added by gstrauss over 5 years ago

Hmm, neither works - its still the same :|

Keep trying. That's a fantastic amount of additional detail that you've provided.

==> Look at the response headers from lighttpd. Look at the request headers the browser is sending and see if it matches mydomain.co.uk. It might have a port number.

RE: Redirect HTTP to HTTPS working in Chrome but not in IE 11 - Added by cpcnw over 5 years ago

I usually provide as much information as requested given precise instructions ;)

From Google Chrome when you point to http://www.mydomain.co.uk - then right click on the page, then click 'Inspect', then click on the 'Network' menu, then refresh the page, then click on the first request at the top of the left panel, then click on 'Headers' in the right panel;

General
Request URL: https://www.mydomain.co.uk/
Request Method: GET
Status Code: 200 OK
Remote Address: 212.159.xxx.xxx:443
Referrer Policy: no-referrer-when-downgrade

Response Headers
HTTP/1.1 200 OK
Content-type: text/html; charset=UTF-8
Content-Length: 757
Date: Tue, 08 Jan 2019 18:09:05 GMT
Server: lighttpd/1.4.45

There is a similar result for the http version with :80 at the end of the ip

I have noticed that Chrome is also no longer redirecting since changing the
above from my first post to my third one. Maybe Chrome just had it cached?

Either way the results now seem inconsistent.

RE: Redirect HTTP to HTTPS working in Chrome but not in IE 11 - Added by cpcnw over 5 years ago

I am certainly no expert on this, and the below could actually be technically incorrect however this is actually what is working for me for the following requirements

1) Non www redirected to www version
2) http redirected to https
3) Works in IE as well as Chrome

$HTTP["host"] =~ "(^|\.)mydomain\.co.uk$" {
    server.document-root        = "/var/www" 
    server.error-handler-404    = "/404.htm" 
}

$HTTP["scheme"] == "http" {
    $HTTP["host"] =~ "(^|\.)mydomain\.co.uk$" {
        url.redirect = ( "^/(.*)" => "https://www.mydomain.co.uk/$1" )
    }
}
    (1-6/6)