Eliminate multiple redirects for www. and https

Hi there:

I ran Google’s speed tests and they pointed out that multiple redirects were happening just as described in this issue.

When I look at the headers when loading “example.com” there are two redirects:

Request URL: http://example.com
Status Code: 307 Internal Redirect
Response: https://example.com

Request URL: https://example.com
Status Code: 301
Response: https://www.example.com

I would prefer to use a netlify.toml file and currently have the following three redirects but am still seeing 2 redirects instead of just 1. I’m wondering if it has anything to do with the status code being 307? Is something outside my control happening before the redirect rules specified in my .toml file are even considered?

Thanks!

[[redirects]]
    from ="http://example.com/*)"
    to = "https://www.example.com/:splat"
    status = 301
    force = true

[[redirects]]    
    from ="http://www.example.com/*"
    to = "https://www.example.com/:splat"
    status = 301
    force = true

[[redirects]]
    from = "https://example.netlify.com/*"
    to = "https://www.example.com/:splat"
    status = 301
    force = true

Hi Ender,

We intentionally redirect http -> https before doing the domain redirect. The HSTS standard requires this:

(see point 1).

You can avoid all redirects by publishing links like https://www.example.com instead of http://example.com :slight_smile:

PS: The 307 redirect is browser-internal, and takes 0 time on the wall clock.