Index: includes/bootstrap.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v
retrieving revision 1.419
diff -u -p -r1.419 bootstrap.inc
--- includes/bootstrap.inc	16 Sep 2010 01:10:38 -0000	1.419
+++ includes/bootstrap.inc	24 Sep 2010 20:24:03 -0000
@@ -2430,6 +2430,8 @@ function language_default($property = NU
  *   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.
@@ -2451,11 +2453,17 @@ 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, the front page is served.
+    // Using basename() here tolerates renaming index.php.
+    if ($path == basename($_SERVER['PHP_SELF'])) {
+      $path = '';
+    }
   }
   else {
     // This is the front page.
Index: modules/system/system.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.test,v
retrieving revision 1.143
diff -u -p -r1.143 system.test
--- modules/system/system.test	24 Sep 2010 00:37:44 -0000	1.143
+++ modules/system/system.test	24 Sep 2010 20:24:03 -0000
@@ -1884,3 +1884,36 @@ class CompactModeTest extends DrupalWebT
     $this->assertTrue($this->cookies['Drupal.visitor.admin_compact_mode']['value'], t('Compact mode persists on new requests.'));
   }
 }
+
+/**
+ * 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();
+    $this->index_php = $GLOBALS['base_url'] . '/index.php';
+  }
+
+  /**
+   * Test index.php handling.
+   */
+  function testIndexPhpHandling() {
+    $this->drupalGet($this->index_php, array('external' => TRUE));
+    $this->assertResponse(200, t('Make sure index.php returns a valid page.'));
+
+    $this->drupalGet($this->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($this->index_php .'/user', array('external' => TRUE));
+    $this->assertResponse(404, t("Make sure index.php/user returns a 'page not found'."));
+  }
+}
+
