If someone can help me how and where I can do the 301 redirect from http to https://www. on a website created with publii and hosted in a hosting.</span>
I’m not sure but I think this is a question for your web hosting company?
The implementation depends on the web server that you are running.
Here is some information for Apache:
As @Verhoeckx said, it depends on your hosting provider. Who is it ?
If you are using Netlfiy, you can use _redirects file and and something like this:
# Redirect default Netlify subdomain to primary domainhttps://ajeet.netlify.com/*https://ajeet.dev/:splat 301!
If you have addedd your domain in Cloudflare, it is easy. Use this guide: