Htaccess需要:http到https - 不存在的文件,文件夹,子域到404 - 只有第一个工作

I need to add rewrites in .htaccess as described in title, but only the first one works, here is how my .htaccess looks now:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /404.php [R,L]

ErrorDocument 404 /404.php

Examples that does not work

These two NON EXISTING SUBDOMAINS examples just hang then show "Unable to connect", but I want them to show REAL 404 error page:

http://nonexisting.example.com
https://nonexisting.example.com

If we enter NON EXISTING FILES or FOLDERS, for example:

https://example.com/nonexistingfile.php
https://example.com/nonexistingfolder/

it shows my 404.php page allright BUT they turn up as a SOFT 404 and I want it to show the REAL 404 error page.

I have tried around 30 different variations of the second Rewrite section without any success. Some code returned a REAL 404 code but showed a messed up page not my 404.php page.

You don't need a rewrite rule here which is just redirecting all non-existing files or directories to /404.php with R=302.

Just try this code:

# will send correct 404 status as well
ErrorDocument 404 /404.php

RewriteEngine On

RewriteCond %{HTTPS} off
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [R=302,NE,L]