Index: wp-includes/load.php
===================================================================
--- wp-includes/load.php	(revision 18997)
+++ wp-includes/load.php	(working copy)
@@ -78,14 +78,18 @@
 		}
 	}
 
-	// Fix for PHP as CGI hosts that set SCRIPT_FILENAME to something ending in php.cgi for all requests
-	if ( isset( $_SERVER['SCRIPT_FILENAME'] ) && ( strpos( $_SERVER['SCRIPT_FILENAME'], 'php.cgi' ) == strlen( $_SERVER['SCRIPT_FILENAME'] ) - 7 ) )
+	// Fix for PHP as CGI hosts that set SCRIPT_FILENAME to something ending in php*.cgi for all requests
+	if ( isset( $_SERVER['SCRIPT_FILENAME'] ) && ( 'php' == substr(basename($_SERVER['SCRIPT_FILENAME']), 0, 3) && '.cgi' == substr(basename($_SERVER['SCRIPT_FILENAME']), -4) ) )
 		$_SERVER['SCRIPT_FILENAME'] = $_SERVER['PATH_TRANSLATED'];
 
-	// Fix for Dreamhost and other PHP as CGI hosts
-	if ( strpos( $_SERVER['SCRIPT_NAME'], 'php.cgi' ) !== false )
+	// Fix for Dreamhost and other PHP as CGI hosts (looks for $_SERVER['SCRIPT_NAME'] = "php*.cgi")
+	if ( 'php' == substr(basename($_SERVER['SCRIPT_NAME']), 0, 3) && '.cgi' == substr(basename($_SERVER['SCRIPT_NAME']), -4) )
 		unset( $_SERVER['PATH_INFO'] );
 
+	// Fix php.cgi as PHP_SELF (looks for $_SERVER['PHP_SELF'] = "php*.cgi")
+	if ( 'php' == substr(basename($_SERVER['PHP_SELF']), 0, 3) && '.cgi' == substr(basename($_SERVER['PHP_SELF']), -4) )
+		$_SERVER['PHP_SELF'] = '';
+	
 	// Fix empty PHP_SELF
 	$PHP_SELF = $_SERVER['PHP_SELF'];
 	if ( empty( $PHP_SELF ) )
