diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc
index 0b25e59..654ffd5 100644
--- a/core/includes/install.core.inc
+++ b/core/includes/install.core.inc
@@ -239,7 +239,7 @@ function install_state_defaults() {
  *   An array of information about the current installation state. This is
  *   modified with information gleaned from the beginning of the page request.
  */
-function install_begin_request(&$install_state) {
+function install_begin_request(&$install_state, $config_verified = NULL) {
   // A request object from the HTTPFoundation to tell us about the request.
   $request = Request::createFromGlobals();
 
@@ -328,7 +328,12 @@ function install_begin_request(&$install_state) {
   \Drupal::setContainer($container);
 
   // Determine whether base system services are ready to operate.
-  $install_state['config_verified'] = install_verify_config_directory(CONFIG_ACTIVE_DIRECTORY) && install_verify_config_directory(CONFIG_STAGING_DIRECTORY);
+  if (isset($config_verified)) {
+    $install_state['config_verified'] = $config_verified;
+  }
+  else {
+    $install_state['config_verified'] = install_verify_config_directory(CONFIG_ACTIVE_DIRECTORY) && install_verify_config_directory(CONFIG_STAGING_DIRECTORY);
+  }
   $install_state['database_verified'] = install_verify_database_settings();
   $install_state['settings_verified'] = $install_state['config_verified'] && $install_state['database_verified'];
 
diff --git a/core/includes/theme.inc b/core/includes/theme.inc
index f98aadd..b8b3a88 100644
--- a/core/includes/theme.inc
+++ b/core/includes/theme.inc
@@ -2633,6 +2633,10 @@ function drupal_common_theme() {
       'variables' => array('content' => NULL, 'show_messages' => TRUE),
       'template' => 'install-page',
     ),
+    'maintenance_access_denied' => array(
+      'variables' => array('script_name' => 'update.php', 'settings_name' => 'update_free_access', 'login' => TRUE, 'postfix' => ''),
+      'template' => 'maintenance-access-denied',
+    ),
     'task_list' => array(
       'variables' => array('items' => NULL, 'active' => NULL,  'variant' => NULL),
     ),
diff --git a/core/includes/theme.maintenance.inc b/core/includes/theme.maintenance.inc
index 3d53ea4..744e171 100644
--- a/core/includes/theme.maintenance.inc
+++ b/core/includes/theme.maintenance.inc
@@ -202,3 +202,23 @@ function theme_authorize_message($variables) {
   }
   return $item;
 }
+
+/**
+ * Prepares variables for maintenance access denied templates.
+ *
+ * Default template: maintenance-access-denied.html.twig.
+ *
+ * @param array $variables
+ *   An associative array containing:
+ *   - script_name: The script name for which access was denied.
+ *   - login: Whether the user can login to allow access.
+ *   - settings_name: The name of the setting in settings.php that can be
+ *     updated to allow access.
+ *   - postfix: Additional text to be rendered at the end.
+ */
+function template_preprocess_maintenance_access_denied(&$variables) {
+  drupal_add_http_header('Status', '403 Forbidden');
+  header(\Drupal::request()->server->get('SERVER_PROTOCOL') . ' 403 Forbidden');
+  watchdog('access denied', $variables['script_name'], NULL, WATCHDOG_WARNING);
+  drupal_set_title('Access denied');
+}
diff --git a/core/modules/system/templates/maintenance-access-denied.html.twig b/core/modules/system/templates/maintenance-access-denied.html.twig
new file mode 100644
index 0000000..29cfadd
--- /dev/null
+++ b/core/modules/system/templates/maintenance-access-denied.html.twig
@@ -0,0 +1,36 @@
+{#
+/**
+ * @file
+ * Default theme implementation for a maintenance access denied message.
+ *
+ * Variables:
+ * - script_name: The script name for which access was denied.
+ * - login: Whether the user can login to allow access.
+ * - settings_name: The name of the setting in settings.php that can be updated
+ *   to allow access.
+ * - postfix: Additional text to be rendered at the end.
+ *
+ * @see template_preprocess_maintenance_access_denied()
+ *
+ * @ingroup themeable
+ */
+#}
+<p>Access denied. You are not authorized to access this page.
+{% if login %}
+  Log in using either an account with the <em>administer software updates</em> permission or the site maintenance account (the account you created during installation). If you cannot log in, you will have to
+{% else %}
+  You need to
+{% endif %}
+edit <code>settings.php</code> to bypass this access check. To do this:</p>
+
+<ol>
+  <li>With a text editor find the settings.php file on your system. From the main Drupal directory that you installed all the files into, go to <code>sites/your_site_name</code> if such directory exists, or else to <code>sites/default</code> which applies otherwise.</li>
+  <li>There is a line inside your settings.php file that says <code>$settings['{{ settings_name }}'] = FALSE;</code>. Change it to <code>$settings['{{ settings_name }}'] = TRUE;</code>.</li>
+  <li>As soon as the {{ script_name }} script is done, you must change the settings.php file back to its original form with <code>$settings['{{ settings_name }}'] = FALSE;</code>.</li>
+  {% if login %}
+    <li>To avoid having this problem in the future, remember to log in to your website using either an account with the <em>administer software updates</em> permission or the site maintenance account (the account you created during installation) before you backup your database at the beginning of the update process.</li>
+  {% endif %}
+  {% if postfix %}
+    <li>{{ postfix }}</li>
+  {% endif %}
+</ol>
diff --git a/core/rebuild.php b/core/rebuild.php
index 9ddf054..33235d2 100644
--- a/core/rebuild.php
+++ b/core/rebuild.php
@@ -19,6 +19,8 @@
 require_once __DIR__ . '/includes/bootstrap.inc';
 require_once __DIR__ . '/includes/utility.inc';
 
+define('MAINTENANCE_MODE', 'update');
+
 drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION);
 
 if (settings()->get('rebuild_access', FALSE) ||
@@ -29,6 +31,27 @@
 
   drupal_rebuild();
   drupal_set_message('Cache rebuild complete.');
+  header('Location: ' . $GLOBALS['base_url']);
+}
+else {
+  require_once DRUPAL_ROOT . '/core/includes/install.core.inc';
+  require_once DRUPAL_ROOT . '/core/includes/update.inc';
+  $install_state = array('interactive' => FALSE) + install_state_defaults();
+  install_begin_request($install_state, FALSE);
+  drupal_add_http_header('Content-Type', 'text/html; charset=utf-8');
+  $content = array(
+    '#theme' => 'maintenance_access_denied',
+    '#script_name' => 'rebuild.php',
+    '#settings_name' => 'rebuild_access',
+    '#login' => FALSE,
+    '#postfix' => 'Read more information, see the <a href="https://drupal.org/documentation/rebuild">handbook</a>.',
+  );
+  $maintenance_page = array(
+    '#theme' => 'maintenance_page',
+    '#content' => drupal_render($content),
+    '#show_messages' => FALSE,
+  );
+  print drupal_render($maintenance_page);
+
 }
 
-header('Location: ' . $GLOBALS['base_url']);
diff --git a/core/update.php b/core/update.php
index 6491afc..7aa3ae2 100644
--- a/core/update.php
+++ b/core/update.php
@@ -216,26 +216,6 @@ function update_info_page() {
 }
 
 /**
- * Renders a 403 access denied page for update.php.
- *
- * @return
- *   Rendered HTML warning with 403 status.
- */
-function update_access_denied_page() {
-  drupal_add_http_header('Status', '403 Forbidden');
-  header(\Drupal::request()->server->get('SERVER_PROTOCOL') . ' 403 Forbidden');
-  watchdog('access denied', 'update.php', NULL, WATCHDOG_WARNING);
-  drupal_set_title('Access denied');
-  return '<p>Access denied. You are not authorized to access this page. Log in using either an account with the <em>administer software updates</em> permission or the site maintenance account (the account you created during installation). If you cannot log in, you will have to edit <code>settings.php</code> to bypass this access check. To do this:</p>
-<ol>
- <li>With a text editor find the settings.php file on your system. From the main Drupal directory that you installed all the files into, go to <code>sites/your_site_name</code> if such directory exists, or else to <code>sites/default</code> which applies otherwise.</li>
- <li>There is a line inside your settings.php file that says <code>$settings[\'update_free_access\'] = FALSE;</code>. Change it to <code>$settings[\'update_free_access\'] = TRUE;</code>.</li>
- <li>As soon as the update.php script is done, you must change the settings.php file back to its original form with <code>$settings[\'update_free_access\'] = FALSE;</code>.</li>
- <li>To avoid having this problem in the future, remember to log in to your website using either an account with the <em>administer software updates</em> permission or the site maintenance account (the account you created during installation) before you backup your database at the beginning of the update process.</li>
-</ol>';
-}
-
-/**
  * Determines if the current user is allowed to run update.php.
  *
  * @return
@@ -438,7 +418,8 @@ function update_task_list($active = NULL) {
   }
 }
 else {
-  $output = update_access_denied_page();
+  $content = array('#theme' => 'maintenance_access_denied');
+  $output = drupal_render($content);
 }
 if (isset($output) && $output) {
   // Explicitly start a session so that the update.php token will be accepted.
