将主URL重定向到HTTPS,将所有子域重定向到HTTP,但保留现有规则

Currently working on something and need assistance with my htaccess file.

I have it set up right now and it's working how I want it where it will remove the trailing slash, and remove .php so it looks like a directory. It also will redirect bar.example.com to a file example.com/thing?foo=bar

I want to make use of the SSL certificate I purchased and force HTTPS on any main domain pages, but force HTTP when visiting the subdomain because my certificate is not a wildcard.

Any help is appreciated, what I currently have is posted below.

RewriteEngine on
Options +FollowSymLinks

RewriteCond %{HTTP_HOST} !^www\.example.com
RewriteCond %{HTTP_HOST} ^(.+).example.com
RewriteRule ^([^/]*)$ http://example.com/thing?foo=%1 [P,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://example.com/$1 [R=301,L]
RewriteRule ^([^/.]+)$ $1.php [L]

Redirect your existing conditions directly to https:// and then add a new rule that checks for %{HTTPS}. See the Apache docs for more information.

RewriteEngine on
Options +FollowSymLinks

RewriteCond %{HTTP_HOST} !^www\.example.com
RewriteCond %{HTTP_HOST} ^(.+).example.com
# CHANGE: Redirect your subdomains directly to the secure target URL
RewriteRule ^([^/]*)$ https://example.com/thing?foo=%1 [P,L]

RewriteCond %{REQUEST_FILENAME} !-d
# CHANGE: same goes for the folders
RewriteRule ^([^/]+)/$ https://example.com/$1 [R=301,L]
RewriteRule ^([^/.]+)$ $1.php [L]

# NEW: Redirect everything else that comes in on `http://www.`
RewriteCond %{HTTP_HOST} ^www\.example.com
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://www.example.com/$1 [R=301,L]