I assume you use the defualt webserver lighttpd, then you can check this out:
https://redmine.lighttpd.net/projects/1/wiki/docs_modrewrite#With-mod_redirect
There was also the same question in the past, it’s worth reading why it’s maybe not so a good idea / make thngs more complicated:
https://dietpi.com/forum/t/nextcloud-sub-domain/5219/3?u=jappe