WordPress .htaccess maintenance mode not working

Solution:

Method #1: Custom code to display a maintenance page

If you want to display a basic maintenance splash page on your site without using a maintenance mode plugin, you can add this bit of code to your functions.php

function wp_maintenance_mode() {
   if (!current_user_can('edit_themes') || !is_user_logged_in()) {
     wp_die('<h1>Under Maintenance</h1><br />Something ain't right, but we're working on it! Check back later.');
   }
}
add_action('get_header', 'wp_maintenance_mode');

Method #2: Enable maintenance mode through your .htaccess file

For this approach it is necessary to have permission to edit the .htaccess file on your server. This file can be found in the root directory of your website. Once you have this file opened, copy and paste the following code:

RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_ADDR} !^111\.111\.111\.111
RewriteCond %{REQUEST_URI} !^/maintenance\.html$
RewriteRule ^(.*)$ https://example.com/maintenance.html [R=307,L]

Method #3: Using WordPress maintenance mode plugins