redirect – SSL and WWW > non-WWW redirection not working on 404 pages in WordPress

I’ve enabled SSL on my WordPress website and set redirection from www to non-WWW via the following code placed in .htaccess:

# REDIRECT WWW TO NON-WWW
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.example.com (NC)
RewriteRule (.*) https://example.com/$1 (L,R=301)
# REDIRECT HTTP TO HTTPS
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} (L,R=301)

It works great everywhere except for 404 pages – not a single 404 page is protected by SSL and won’t redirect WWW to non-www. Does anyone have any idea how to fix this?