For these types of stuff, redirecting www to apex domain and redirecting http to https, it can be achieved via DNS provider.
For example, if you are using Cloudflare, you can make the follwing redirect rules.
Redirect www to apex
When incoming requests match
Wildcard pattern
Request URL: https://www.*
Then
Target URL: https://${1}
Status code: 301
Preserve query string: Enabled
Redirect http to https
If incoming requests match:
Wildcard pattern
Request URL: http://*
Then:
Target URL: https://${1}
Status code: 301
Preserve query string: Enabled
The actual implementation might vary depending on your DNS provider.
References: