.htaccess: How to redirect all subpages to a maintenance page?

If a website that is already indexed in search engines is revised or generally shut down for the time being, it may make sense to redirect all previous pages to a start page or maintenance page. By adjusting the .htaccess file in the main directory of the website, this is quite easy.

From an SEO point of view, this variant is not recommended, as it can automatically lead to ranking losses. However, in cases where this can be neglected, this code snippet is quite helpful.

RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_URI} !^/(index\.html|bg\.jpg)?$ [NC]
RewriteCond %{REQUEST_URI} !^/img(/|$) [NC]
RewriteRule ^.*$ /index.html [L,R=301]
Without cookies
This website does not use cookies or tracking. More information can be found in the privacy policy.