Unable to 301 redirect in .htaccess

Searched the web and found few variations of the RewriteCond & RewriteRule to 301 redirect www.cloud.domain.com/* to http(s)://cloud.domain.com/* (not changing the path) but I am stuck on every try and the redirects dont work - “www.” opens as before.

Do anybody have an idea if something can prevent the redirect of happening? How to fix the issue if the problem is not in this particular module of .htaccess?

here is my code snippet:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_USER_AGENT} DavClnt
RewriteRule ^$ /remote.php/webdav/ [L,R=302]
RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteRule ^.well-known/carddav /remote.php/dav/ [R=301,L]
RewriteRule ^.well-known/caldav /remote.php/dav/ [R=301,L]
RewriteRule ^remote/(.) remote.php [QSA,L]
RewriteRule ^(?:build|tests|config|lib|3rdparty|templates)/.
- [R=404,L]
RewriteRule ^.well-known/(?!acme-challenge|pki-validation) /index.php [QSA,L]
RewriteRule ^(?:.(?!well-known)|autotest|occ|issue|indie|db_|console).* - [R=404,L]
RewriteCond %{HTTP_HOST} ^staticIP$
RewriteRule ^(.*)$ https://cloud.domain.com/$1 [L,R=301]
# Redirect to non-www
RewriteCond %{HTTP_HOST} ^www.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]

tried few variations of the last 2 rows (even changing their place in the begining) and this doesn’t seem to help, so I will be thankful for code corrections, but I don’t believe this will resolve the issue.

Thank you in advance!

Okay, so instead of thinking what could possible prevent the redirect, let’s think about where the redirects happen? Which services/files can store rules for NC redirects, except the .htaccess file in main NC folder?

I have my rules in this order now:

First I redirect my static IP to https://domain.com, if someone tries to visit my NC by IP (this works)

Second I check if the url is www and if it is I redirect to non-www (http)

And at last I have a redirect for http->https (also works)

My problem now is that whenever I type www.domain.com, I get redirected to https://www.domain.com, which is not included in my SSL and browser gives a warning of a non-secure website.