Netlify does allow you to force TLS. It is recommended to not 'force TLS' until you are certain all URL's work with https
Don’t check the ‘force TLS’ option until you are certain that all of your URL’s work with an ‘https://’ in front!
Why?
Once you force TLS using Netlify they will set the STS (Strict-Transport-Security) header in your page response headers. I will not go through the explanation but you can read about it here.
The main thing to know is:
Once a supported browser receives this header that browser will prevent any communications from being sent over HTTP to the specified domain and will instead send all communications over HTTPS
Note that Netlify's settings (using the force TLS checkbox) are to have the visiting browsers enforce this for 1 year past visit date! So, if you have anything that fails on https, your site is going to have some issues until you are able to fix them.
Wait!
You still want your site to always serve up https pages once you add the certificate, but not have it forced while testing or working through issues.
Solution:
Use the _redirects
file at the root of your deployed site (in your "Publish directory, next to index.html) to redirect traffic to https.
Here is an example of the file
_redirects
# redirect netlify sitename to your sitename for SEO purposes,
# to avoid duplicate content. Do this for http and https
https://example.netlify.com/* https://www.example.com/:splat 301!
http://example.netlify.com/* http://www.example.com/:splat 301!
# also redirect http to https for your custom domain.
# Note that netlify automatically redirects to your custom domain from the bare domain (or vice versa), so you only need one rule here.
http://www.example.com/* https://www.example.com/:splat 301!
Or the same redirects using Structured Redirects
netlify.toml
[[redirects]]
from = "https://example.netlify.com/*"
to = "https://www.example.com/:splat"
status = 301
force = true
[[redirects]]
from = "http://example.netlify.com/*"
to = "http://www.example.com/:splat"
status = 301
force = true
[[redirects]]
from = "http://www.example.com/*"
to = "https://www.example.com/:splat"
status = 301
force = true
NOTE:
- Netlify already redirects the bare domain to
www
subdomain (optional)
- It's recommended to use
www
as your custom domain, to take full advantage of Netlify CDN with ANY DNS setup.
- redirects the netlify subdomain site to custom domain (optional)
- redirects
http
to https
for all paths