diff --git a/core/modules/system/tests/installer.test b/core/modules/system/tests/installer.test
index f076ba9..62a8aff 100644
--- a/core/modules/system/tests/installer.test
+++ b/core/modules/system/tests/installer.test
@@ -50,3 +50,30 @@ class InstallerLanguageTestCase extends WebTestBase {
   }
 
 }
+
+class InstallerRedirectTestCase extends WebTestBase {
+
+  public static function getInfo() {
+    return array(
+      'name' => 'Installer redirect test',
+      'description' => 'Tests whether removing the {system} table results in an installer redirect.',
+      'group' => 'Installer',
+    );
+  }
+
+  /**
+   * Tests whether removing the {system} table results in an installer redirect.
+   */
+  function testInstallerRedirect() {
+    // Rename the system table out of the way.
+    db_rename_table('system', 'system_temp');
+
+    // Load the main page, which should redirect to the installer.
+    $this->drupalGet('');
+    $this->assertNotIdentical(strpos($this->getUrl(), 'core/install.php'), FALSE, 'The user is redirected to the installer when the {system} table is missing.');
+
+    // Rename the system table back.
+    db_rename_table('system_temp', 'system');
+  }
+
+}
diff --git a/index.php b/index.php
index b91fb1e..e777d61 100644
--- a/index.php
+++ b/index.php
@@ -17,5 +17,17 @@
 define('DRUPAL_ROOT', getcwd());
 
 require_once DRUPAL_ROOT . '/core/includes/bootstrap.inc';
-drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
+
+try {
+  drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
+}
+catch (PDOException $e) {
+  // A PDO exception might mean that we are running on an empty database. In
+  // that case, just redirect the user to install.php.
+  if (!db_table_exists('system')) {
+    include_once DRUPAL_ROOT . '/core/includes/install.inc';
+    install_goto('core/install.php');
+  }
+  throw $e;
+}
 menu_execute_active_handler();
