Cloudflare SSL cert is installed and I need to redirect to HTTPS not HTTP

Netlify name: trusting-tesla-b1b67c
Domain: Custom domain not controlled by Netlify.

I have connected a sub-domain to netlify and have chosen to not have Netlify control DNS. When the Sub-domain was created Cloudflare auto-generated an SSL. There are currently 2 versions of the site that are live an HTTP and HTTPS (cloud flare). How do I redirect to the HTTPS version via the .toml file? or do I have to re-generate the certificate and install it via Netlifys panel?

Hi @augdog978

Domain-level Redirects is what you are requiring for this. The example in the documentation uses _redirects syntax.

netlify.toml Example:

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

@coelmay Whats :splat?
Also, the application is Reactjs, would the user still be able to navigate to other pages?

:splat is explained in the documentation previously linked.

An asterisk indicates a splat that will match anything that follows it.


With SPAs such as React you need a rewrite as explained here. In a netlify.toml the syntax is

[[redirects]]
  from = "/*"
  to = "/index.html"
  status = 200

This rule must go last (previous rule must go first.)

I believe these two rules together will work as desired in directing all HTTP traffic to HTTPS and allow React to do the routing, however not having a HTTP site to test on, I cannot say for certain.

Yes, I did exactly that and it worked. You have been an amazing help, thank you!

Whats the best way to account for www in the .toml file?

You would need to create a second rule in addition to the previous.

Example

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

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

[[redirects]]
  from = "/*"
  to = "/index.html"
  status = 200

If you wished to have the www present in the URL the user sees you would change the to value e.g.

to = "https://www.example.com/:splat
1 Like