diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc
index 2809d10f344791d18eb2618f7c920639a6b9b3b6..29cb7382780a0fc84f7e8d461a78655e21d430a7 100644
--- a/includes/bootstrap.inc
+++ b/includes/bootstrap.inc
@@ -2363,6 +2363,8 @@ function language_default($property = NULL) {
  *   base_path() returns "/drupalfolder/".
  * - http://example.com/path/alias (which is a path alias for node/306) returns
  *   "path/alias" as opposed to the internal path.
+ * - http://example.com/index.php returns an empty string (meaning: front page).
+ * - http://example.com/index.php?page=1 returns an empty string.
  *
  * @return
  *   The requested Drupal URL path.
@@ -2384,11 +2386,19 @@ function request_path() {
     $path = $_GET['q'];
   }
   elseif (isset($_SERVER['REQUEST_URI'])) {
-    // This is a request using a clean URL. Extract the path from REQUEST_URI.
+    // This request is either a clean URL, or 'index.php', or nonsense.
+    // Extract the path from REQUEST_URI.
     $request_path = strtok($_SERVER['REQUEST_URI'], '?');
     $base_path_len = strlen(rtrim(dirname($_SERVER['SCRIPT_NAME']), '\/'));
     // Unescape and strip $base_path prefix, leaving q without a leading slash.
     $path = substr(urldecode($request_path), $base_path_len + 1);
+    // If the path equals the script filename, either because 'index.php' was
+    // explicitly provided in the URL, or because the server added it to
+    // $_SERVER['REQUEST_URI'] even when it wasn't provided in the URL (some
+    // versions of Microsoft IIS do this), the front page should be served.
+    if ($path == basename($_SERVER['PHP_SELF'])) {
+      $path = '';
+    }
   }
   else {
     // This is the front page.
diff --git a/modules/system/system.test b/modules/system/system.test
index 583dd6db4b5f5c794e994224fb856e113e544d24..125cb8faa2a9ef5174bec14db3163faf43837b24 100644
--- a/modules/system/system.test
+++ b/modules/system/system.test
@@ -2178,3 +2178,37 @@ class SystemAuthorizeCase extends DrupalWebTestCase {
     $this->assertText('System Test Username');
   }
 }
+
+/**
+ * Test the handling of requests containing 'index.php'.
+ */
+class SystemIndexPhpTest extends DrupalWebTestCase {
+  public static function getInfo() {
+    return array(
+      'name' => 'Index.php handling',
+      'description' => "Test the handling of requests containing 'index.php'.",
+      'group' => 'System',
+    );
+  }
+
+  function setUp() {
+    parent::setUp();
+  }
+
+  /**
+   * Test index.php handling.
+   */
+  function testIndexPhpHandling() {
+    $index_php = $GLOBALS['base_url'] . '/index.php';
+
+    $this->drupalGet($index_php, array('external' => TRUE));
+    $this->assertResponse(200, t('Make sure index.php returns a valid page.'));
+
+    $this->drupalGet($index_php, array('external' => TRUE, 'query' => array('q' => 'user')));
+    $this->assertResponse(200, t('Make sure index.php?q=user returns a valid page.'));
+
+    $this->drupalGet($index_php .'/user', array('external' => TRUE));
+    $this->assertResponse(404, t("Make sure index.php/user returns a 'page not found'."));
+  }
+}
+