1. is solved with both DNS and web server setting. Usually, DNS names example.com and www
.example
.com resolve to the same IP. Then the webserver has to redirect example.com to w
ww.example.com. This is an advanced configuration. I think, but I may be wrong, that it cannot be done in htaccess.
2. is a complex task that is not DokuWiki specific and that cannot be done in htaccess. The best is you ask your search engine and/or find some system administration forum dedicated to your system and webserver where you will get help. The helpdesk of your webhoster is probably a good starting point.
2bis "not insert 'doku.php?id' in that link." : Good news : This has nothing to do with protocol (HTTP/HTTPS). There is a dedicated page on DokuWiki Wiki. See
https://www.dokuwiki.org/rewrite