RewriteEngine On

# Check if the request is coming from HTTP, and redirect to HTTPS
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Custom 404 error page
ErrorDocument 404 /404.shtml