How to do a redirect in htaccess dynamic subdomain with www to without www subdomain?

Good afternoon.
Some days I redirect subdomains.

The main mirror site
The subdomains are dynamic and should be without the www (www is already level 4, and WildCard does not work) of the form: *

RewriteEngine On
#Redirect main domain without www to with www is Working normally
RewriteCond %{HTTP_HOST} ^sait\.ru$ [NC]
RewriteRule ^(.*)$$1 [R=301,L]

# subdomains without www (not a rule)
RewriteCond %{HTTP_HOST} ^www\.([A-Za-z0-9_-]*)\.sait\.ru
RewriteRule ^(.*)$$1 [R=permanent,L]

Please help, can who faced, all head broke already with them. In theory it should work the second rule, but no.
June 10th 19 at 15:39
1 answer
June 10th 19 at 15:41
RewriteCond %{ENV:HTTPS} on
 #check the website now available over https
RewriteRule .* - [E=SSL:s]
 #Create a variable ssl with text "s" no in the headers of the https text so you have izgolyatsya

RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
 # Check whether the domain www URL. 
RewriteRule ^(.*)$ http%{ENV:SSL}://%1/$1 [R=301,L]
 # Redirect www to be deleted, and then inserted s if the first condition worked
The meaning is muddied in order to throw a link with the preservation Protocol.
Gluing http - >https in a separate rule.
In your case if they are already defined some of the terms you can remove this rule.
Victor, thanks for otlichalis. To check a rule can a little later.
But I understand this rule, all links that start with www to without www send?

And I need to primary domain remained at www.

Or am I mistaken ?

Redirect to https I have enabled via the isp panel, configure the domain to redirect to https - Alayna commented on June 10th 19 at 15:44
RewriteCond %{ENV:HTTPS} on
RewriteRule .* - [E=SSL:s]

RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteCond %{HTTP_HOST} ^!www\.sait\.ru$ [NC]
RewriteRule ^(.*)$ http%{ENV:SSL}://%1/$1 [R=301,L]

Add denial !
Will And And not - Lavern_Schuppe commented on June 10th 19 at 15:47

Thanks for the help. The result was as it was initially only in the ISP panel, removed a Daw in settings of a domain "Redirect HTTP requests to HTTPS"

And added htaccess
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Can someone come in handy - Alayna commented on June 10th 19 at 15:50

Find more questions by tags htaccess1C-Bitrix