There are two ways to set the mod rewrite: in the .conf file or in the .htaccess file.

To make the change in the .conf in effect, you need to service httpd restart. The change in .htaccess will take effects immediately. Besides, .htaccess only affects the requests in that folder.

The options that can be modified by .htaccess is specified by the AllowOverride option. It can only be put inside the <Directory> section. For Apache before 2.3.9 the default value is All, and since that it is None. The official document check here:

    https://httpd.apache.org/docs/2.4/mod/core.html#allowoverride

To make my rewrite rules effective in the whole site, I put them in the .conf file.

(1) Direct the subdomain to https + sub folder
(2) If there is no subdomain, direct it to the https

  RewriteEngine On
  RewriteEngine On
  RewriteCond %{HTTP_HOST} ^(.*)\.(.*\..*)<img src="https://dingxf.cn/blog/wp-content/ql-cache/quicklatex.com-4129c0cc539b93a321a3052399fd9525_l3.png" class="ql-img-inline-formula quicklatex-auto-format" alt="&#91;&#78;&#67;&#93; &#32;&#32;&#82;&#101;&#119;&#114;&#105;&#116;&#101;&#82;&#117;&#108;&#101;&#32;&#94;&#40;&#46;&#42;&#41;" title="Rendered by QuickLaTeX.com" height="22" width="166" style="vertical-align: -5px;"/> https://%2/%1%{REQUEST_URI} [L,R=301]
  RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

That’s all. Enjoy.

Key words:
rewrite subdomain to sub folder
redirect http to https
rewrite http to https