How to implement dynamic subdomains only for https?

How to redirect from http to https and use the mod_rewrite rule just for https? Separately works.

Forwarding of this type:
http://demo.example.com => https://demo.example.com

And save the modrewrite rule of the form:
https://demo.example.com => https://example.com/index.php?id=demo

There is this htaccess, but it does not solve the problem.
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{HTTP_HOST} ^(.{2,})\.example.com$
RewriteRule (.*) https://example.com/index.php?id=%1 [P,L]
June 5th 19 at 21:45
1 answer
June 5th 19 at 21:47
1. I've painted a bunch of examples you should go.
https://klondike-studio.ru/standards/standartnyy-h...

Also you forgot to add the condition in the second rule, do not forget that primitive may be several in a row.

RewriteEngine On

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^(.{2,})\.example.com$
RewriteRule (.*) https://example.com/index.php?id=%1 [P,L]
RewriteCond %{HTTP_HOST} ^(.{2,})\.example.com$
under this rule suitable www.example.com - Lavern_Schuppe commented on June 5th 19 at 21:50

Find more questions by tags htaccessProcessing URL