Index: wp-pass.php
===================================================================
--- wp-pass.php	(revision 3569)
+++ wp-pass.php	(working copy)
@@ -1,5 +1,7 @@
 <?php
-require( dirname(__FILE__) . '/wp-config.php');
+require_once( dirname(__FILE__) . '/wp-functions.php');
+$conffile = get_conf();
+require_once($conffile);
 
 if ( get_magic_quotes_gpc() )
 	$_POST['post_password'] = stripslashes($_POST['post_password']);
@@ -8,4 +10,4 @@
 setcookie('wp-postpass_' . COOKIEHASH, $_POST['post_password'], time() + 864000, COOKIEPATH);
 
 wp_redirect($_SERVER['HTTP_REFERER']);
-?>
\ No newline at end of file
+?>
Index: wp-rss.php
===================================================================
--- wp-rss.php	(revision 3569)
+++ wp-rss.php	(working copy)
@@ -1,7 +1,9 @@
 <?php
 
 if (empty($wp)) {
-	require_once('wp-config.php');
+	require_once( dirname(__FILE__) . '/wp-functions.php');
+	$conffile = get_conf();
+	require_once($conffile);
 	wp('feed=rss');
 }
 
Index: wp-login.php
===================================================================
--- wp-login.php	(revision 3569)
+++ wp-login.php	(working copy)
@@ -1,5 +1,7 @@
 <?php
-require( dirname(__FILE__) . '/wp-config.php' );
+require_once( dirname(__FILE__) . '/wp-functions.php');
+$conffile = get_conf();
+require_once($conffile);
 
 $action = $_REQUEST['action'];
 $error = '';
Index: wp-comments-post.php
===================================================================
--- wp-comments-post.php	(revision 3569)
+++ wp-comments-post.php	(working copy)
@@ -1,5 +1,7 @@
 <?php
-require( dirname(__FILE__) . '/wp-config.php' );
+require_once( dirname(__FILE__) . '/wp-functions.php');
+$conffile = get_conf();
+require_once($conffile);
 
 nocache_headers();
 
Index: wp-functions.php
===================================================================
--- wp-functions.php	(revision 0)
+++ wp-functions.php	(revision 0)
@@ -0,0 +1,47 @@
+<?php
+/**
+ * Locate the appropriate configuration file.
+ *
+ * Try finding a matching configuration file by stripping the website's
+ * hostname from left to right and pathname from right to left. The first
+ * configuration file found will be used, the remaining will ignored. If no
+ * configuration file is found, return a default value 'wp-config.php'.
+ *
+ * Example for a fictitious site installed at
+ * http://www.example.com:8080/mysite/test/ the config file is searched in
+ * the following names:
+ *
+ *  1. 8080.www.example.com.mysite.test-config.php
+ *  2. www.example.com.mysite.test-config.php
+ *  3. example.com.mysite.test-config.php
+ *  4. org.mysite.test-config.php
+ *
+ *  5. 8080.www.example.com.mysite-config.php
+ *  6. www.example.com.mysite-config.php
+ *  7. example.com.mysite-config.php
+ *  8. org.mysite-config.php
+ *
+ *  9. 8080.www.example.com-config.php
+ * 10. www.example.com-config.php
+ * 11. example.com-config.php
+ * 12. com-config.php
+ *
+ * 13. wp-config.php
+ */
+function get_conf() {
+
+$uri = explode('/', $_SERVER['PHP_SELF']);
+$server = explode('.', rtrim($_SERVER['HTTP_HOST'], '.'));
+	for ($i = count($uri) - 1; $i > 0; $i--) {
+		for ($j = count($server); $j > 0; $j--) {
+			$site = implode('.', array_slice($server, -$j)) . implode('.', array_slice($uri, 0, $i));
+			if (file_exists(dirname(__FILE__) . '/'.$site.'-config.php')) {
+				$conf = $site."-config.php";
+				return $conf;
+			}
+		}
+	}
+$conf = "wp-config.php";
+return $conf;
+} 
+?>
Index: wp-blog-header.php
===================================================================
--- wp-blog-header.php	(revision 3569)
+++ wp-blog-header.php	(working copy)
@@ -1,15 +1,19 @@
 <?php
 
 if (! isset($wp_did_header)):
-if ( !file_exists( dirname(__FILE__) . '/wp-config.php') ) {
+
+require_once( dirname(__FILE__) . '/wp-functions.php');
+$conffile = get_conf();
+
+if ( !file_exists( dirname(__FILE__) . '/' . $conffile) ) {
 	if ( strstr( $_SERVER['PHP_SELF'], 'wp-admin') ) $path = '';
 	else $path = 'wp-admin/';
-    die("There doesn't seem to be a <code>wp-config.php</code> file. I need this before we can get started. Need more help? <a href='http://wordpress.org/docs/faq/#wp-config'>We got it</a>. You can <a href='{$path}setup-config.php'>create a <code>wp-config.php</code> file through a web interface</a>, but this doesn't work for all server setups. The safest way is to manually create the file.");
+    die("There doesn't seem to be a <code>$conffile</code> file. I need this before we can get started. Need more help? <a href='http://wordpress.org/docs/faq/#wp-config'>We got it</a>. You can <a href='{$path}setup-config.php'>create a <code>$conffile</code> file through a web interface</a>, but this doesn't work for all server setups. The safest way is to manually create the file.");
 }
 
 $wp_did_header = true;
 
-require_once( dirname(__FILE__) . '/wp-config.php');
+require_once( dirname(__FILE__) . '/' .  $conffile);
 
 wp();
 gzip_compression();
@@ -18,4 +22,4 @@
 
 endif;
 
-?>
\ No newline at end of file
+?>
Index: wp-rdf.php
===================================================================
--- wp-rdf.php	(revision 3569)
+++ wp-rdf.php	(working copy)
@@ -1,7 +1,9 @@
 <?php /* RDF 1.0 generator, original version by garym@teledyn.com */
 
 if (empty($wp)) {
-	require_once('wp-config.php');
+	require_once( dirname(__FILE__) . '/wp-functions.php');
+	$conffile = get_conf();
+	require_once($conffile);
 	wp('feed=rdf');
 }
 
Index: wp-includes/wp-db.php
===================================================================
--- wp-includes/wp-db.php	(revision 3569)
+++ wp-includes/wp-db.php	(working copy)
@@ -5,6 +5,9 @@
 //  Justin Vincent (justin@visunet.ie)
 //	http://php.justinvincent.com
 
+require_once('../wp-functions.php');
+$conffile = get_conf();
+
 define('EZSQL_VERSION', 'WP1.25');
 define('OBJECT', 'OBJECT', true);
 define('ARRAY_A', 'ARRAY_A', false);
@@ -44,7 +47,7 @@
 		if (!$this->dbh) {
 			$this->bail("
 <h1>Error establishing a database connection</h1>
-<p>This either means that the username and password information in your <code>wp-config.php</code> file is incorrect or we can't contact the database server at <code>$dbhost</code>. This could mean your host's database server is down.</p>
+<p>This either means that the username and password information in your <code>".$conffile."</code> file is incorrect or we can't contact the database server at <code>$dbhost</code>. This could mean your host's database server is down.</p>
 <ul>
 	<li>Are you sure you have the correct username and password?</li>
 	<li>Are you sure that you have typed the correct hostname?</li>
@@ -360,4 +363,4 @@
 }
 
 $wpdb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
-?>
\ No newline at end of file
+?>
Index: wp-includes/js/tinymce/wp-mce-help.php
===================================================================
--- wp-includes/js/tinymce/wp-mce-help.php	(revision 3569)
+++ wp-includes/js/tinymce/wp-mce-help.php	(working copy)
@@ -1,7 +1,8 @@
 <?php
+require_once('../../../wp-functions.php');
+$conffile = get_conf();
+require_once('../../../'$conffile);
 
-require_once('../../../wp-config.php');
-
 ?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">
Index: wp-includes/js/tinymce/tiny_mce_gzip.php
===================================================================
--- wp-includes/js/tinymce/tiny_mce_gzip.php	(revision 3569)
+++ wp-includes/js/tinymce/tiny_mce_gzip.php	(working copy)
@@ -17,8 +17,11 @@
 	 */
 
 	/* Heavily edited to add flexibilty in WordPress */
-	@ require('../../../wp-config.php');
+	@ require_once('../../../wp-functions.php');
+	$conffile = get_conf();
+	@ require_once('../../../'$conffile);
 
+
 	function wp_translate_tinymce_lang($text) {
 		if ( ! function_exists('__') ) {
 			return $text;
Index: xmlrpc.php
===================================================================
--- xmlrpc.php	(revision 3569)
+++ xmlrpc.php	(working copy)
@@ -9,7 +9,9 @@
 if ( isset($HTTP_RAW_POST_DATA) )
 	$HTTP_RAW_POST_DATA = trim($HTTP_RAW_POST_DATA);
 
-include('./wp-config.php');
+require_once( dirname(__FILE__) . '/wp-functions.php');
+$conffile = get_conf();
+require_once($conffile);
 
 if ( isset( $_GET['rsd'] ) ) { // http://archipelago.phrasewise.com/rsd 
 header('Content-type: text/xml; charset=' . get_settings('blog_charset'), true);
Index: wp-mail.php
===================================================================
--- wp-mail.php	(revision 3569)
+++ wp-mail.php	(working copy)
@@ -1,5 +1,7 @@
 <?php
-require(dirname(__FILE__) . '/wp-config.php');
+require_once( dirname(__FILE__) . '/wp-functions.php');
+$conffile = get_conf();
+require_once($conffile);
 
 require_once(ABSPATH.WPINC.'/class-pop3.php');
 
@@ -163,4 +165,4 @@
 
 $pop3->quit();
 
-?>
\ No newline at end of file
+?>
Index: wp-register.php
===================================================================
--- wp-register.php	(revision 3569)
+++ wp-register.php	(working copy)
@@ -1,5 +1,8 @@
 <?php
-require('./wp-config.php');
+require_once( dirname(__FILE__) . '/wp-functions.php');
+$conffile = get_conf();
+require_once($conffile);
+
 require_once( ABSPATH . WPINC . '/registration-functions.php');
 
 $action = $_REQUEST['action'];
Index: wp-trackback.php
===================================================================
--- wp-trackback.php	(revision 3569)
+++ wp-trackback.php	(working copy)
@@ -1,7 +1,9 @@
 <?php
 
 if (empty($wp)) {
-	require_once('wp-config.php');
+	require_once( dirname(__FILE__) . '/wp-functions.php');
+	$conffile = get_conf();
+	require_once($conffile);
 	wp('tb=1');
 }
 
@@ -95,4 +97,4 @@
 	do_action('trackback_post', $wpdb->insert_id);
 	trackback_response(0);
 }
-?>
\ No newline at end of file
+?>
Index: wp-rss2.php
===================================================================
--- wp-rss2.php	(revision 3569)
+++ wp-rss2.php	(working copy)
@@ -1,7 +1,9 @@
 <?php
 
 if (empty($wp)) {
-	require_once('wp-config.php');
+	require_once( dirname(__FILE__) . '/wp-functions.php');
+	$conffile = get_conf();
+	require_once($conffile);
 	wp('feed=rss2');
 }
 
Index: wp-commentsrss2.php
===================================================================
--- wp-commentsrss2.php	(revision 3569)
+++ wp-commentsrss2.php	(working copy)
@@ -1,7 +1,9 @@
 <?php 
 
 if (empty($wp)) {
-	require_once('wp-config.php');
+	require_once( dirname(__FILE__) . '/wp-functions.php');
+	$conffile = get_conf();
+	require_once($conffile);
 	wp('feed=rss2&withcomments=1');
 }
 
Index: wp-atom.php
===================================================================
--- wp-atom.php	(revision 3569)
+++ wp-atom.php	(working copy)
@@ -1,7 +1,9 @@
 <?php
 
 if (empty($wp)) {
-	require_once('wp-config.php');
+	require_once( dirname(__FILE__) . '/wp-functions.php');
+	$conffile = get_conf();
+	require_once($conffile);
 	wp('feed=atom');
 }
 
Index: wp-admin/update-links.php
===================================================================
--- wp-admin/update-links.php	(revision 3569)
+++ wp-admin/update-links.php	(working copy)
@@ -1,5 +1,8 @@
 <?php
-require_once( dirname( dirname(__FILE__) ) . '/wp-config.php');
+require_once('../wp-functions.php');
+$conffile = get_conf();
+require_once('../'$conffile);
+
 require_once( ABSPATH . 'wp-includes/class-snoopy.php');
 
 if ( !get_option('use_linksupdate') )
Index: wp-admin/list-manipulation.php
===================================================================
--- wp-admin/list-manipulation.php	(revision 3569)
+++ wp-admin/list-manipulation.php	(working copy)
@@ -1,5 +1,8 @@
 <?php
-require_once('../wp-config.php');
+require_once('../wp-functions.php');
+$conffile = get_conf();
+require_once('../'$conffile);
+
 require_once('admin-functions.php');
 require_once('admin-db.php');
 
Index: wp-admin/edit-form-ajax-cat.php
===================================================================
--- wp-admin/edit-form-ajax-cat.php	(revision 3569)
+++ wp-admin/edit-form-ajax-cat.php	(working copy)
@@ -1,5 +1,8 @@
 <?php
-require_once('../wp-config.php');
+require_once('../wp-functions.php');
+$conffile = get_conf();
+require_once('../'$conffile);
+
 require_once('admin-functions.php');
 require_once('admin-db.php');
 
@@ -32,4 +35,4 @@
 
 die( (string) $return );
 
-?>
\ No newline at end of file
+?>
Index: wp-admin/install-helper.php
===================================================================
--- wp-admin/install-helper.php	(revision 3569)
+++ wp-admin/install-helper.php	(working copy)
@@ -1,5 +1,8 @@
 <?php
-require_once('../wp-config.php');
+require_once('../wp-functions.php');
+$conffile = get_conf();
+require_once('../'$conffile);
+
 $debug = 0;
 
 /**
@@ -149,4 +152,4 @@
 }
 echo "</pre>";
 */
-?>
\ No newline at end of file
+?>
Index: wp-admin/admin.php
===================================================================
--- wp-admin/admin.php	(revision 3569)
+++ wp-admin/admin.php	(working copy)
@@ -1,8 +1,14 @@
 <?php
-if ( defined('ABSPATH') )
-	require_once( ABSPATH . 'wp-config.php');
-else
-    require_once('../wp-config.php');
+if ( defined('ABSPATH') ) {
+	require_once( ABSPATH . 'wp-functions.php');
+	$conffile = get_conf();
+	require_once(ABSPATH . $conffile);
+}
+else {
+	require_once('../wp-functions.php');
+	$conffile = get_conf();
+	require_once('../'$conffile);
+}
 
 if ( get_option('db_version') != $wp_db_version )
 	die (sprintf(__("Your database is out-of-date.  Please <a href='%s'>upgrade</a>."), get_option('siteurl') . '/wp-admin/upgrade.php'));
Index: wp-admin/templates.php
===================================================================
--- wp-admin/templates.php	(revision 3569)
+++ wp-admin/templates.php	(working copy)
@@ -1,4 +1,7 @@
 <?php
+require_once('../wp-functions.php');
+$conffile = get_conf();
+
 require_once('admin.php');
 $title = __('Template &amp; File Editing');
 $parent_file = 	'edit.php';
@@ -64,7 +67,7 @@
 	if ( ! current_user_can('edit_files') )
 	die('<p>'.__('You have do not have sufficient permissions to edit templates for this blog.').'</p>');
 
-	if ( strstr( $file, 'wp-config.php' ) )
+	if ( strstr( $file, $conffile ) )
 	die('<p>'.__('The config file cannot be edited or viewed through the web interface. Sorry!').'</p>');
 
 	update_recently_edited($file);
Index: wp-admin/execute-pings.php
===================================================================
--- wp-admin/execute-pings.php	(revision 3569)
+++ wp-admin/execute-pings.php	(working copy)
@@ -1,7 +1,8 @@
 <?php
+require_once('../wp-functions.php');
+$conffile = get_conf();
+require_once('../'$conffile);
 
-require_once('../wp-config.php');
-
 // Do pingbacks
 while ($ping = $wpdb->get_row("SELECT * FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_pingme' LIMIT 1")) {
 	$wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE post_id = {$ping->ID} AND meta_key = '_pingme';");
Index: wp-admin/upgrade.php
===================================================================
--- wp-admin/upgrade.php	(revision 3569)
+++ wp-admin/upgrade.php	(working copy)
@@ -1,7 +1,11 @@
 <?php
+require_once('../wp-functions.php');
+$conffile = get_conf();
+
 define('WP_INSTALLING', true);
-if (!file_exists('../wp-config.php')) die("There doesn't seem to be a wp-config.php file. Double check that you updated wp-config-sample.php with the proper database connection information and renamed it to wp-config.php.");
-require('../wp-config.php');
+if (!file_exists('../'.$conffile)) die("There doesn't seem to be a ".$conffile." file. Double check that you updated wp-config-sample.php with the proper database connection information and renamed it to ".$conffile.".");
+
+require('../'.$conffile);
 timer_start();
 require_once(ABSPATH . '/wp-admin/upgrade-functions.php');
 
Index: wp-admin/setup-config.php
===================================================================
--- wp-admin/setup-config.php	(revision 3569)
+++ wp-admin/setup-config.php	(working copy)
@@ -1,14 +1,17 @@
 <?php
 define('WP_INSTALLING', true);
 
-if (file_exists('../wp-config.php')) 
-	die("The file 'wp-config.php' already exists. If you need to reset any of the configuration items in this file, please delete it first. You may try <a href='install.php'>installing now</a>.");
+require_once('../wp-functions.php');
+$conffile = get_conf();
 
+if (file_exists('../'.$conffile)) 
+	die("The file '$conffile' already exists. If you need to reset any of the configuration items in this file, please delete it first. You may try <a href='install.php'>installing now</a>.");
+
 if (!file_exists('../wp-config-sample.php'))
     die('Sorry, I need a wp-config-sample.php file to work from. Please re-upload this file from your WordPress installation.');
 $configFile = file('../wp-config-sample.php');
 
-if (!is_writable('../')) die("Sorry, I can't write to the directory. You'll have to either change the permissions on your WordPress directory or create your wp-config.php manually.");
+if (!is_writable('../')) die("Sorry, I can't write to the directory. You'll have to either change the permissions on your WordPress directory or create your $conffile manually.");
 
 $step = 0;
 if(isset($_GET['step'])) $step = $_GET['step'];
@@ -62,7 +65,7 @@
   <li>Database host</li> 
   <li>Table prefix (if you want to run more than one WordPress in a single database) </li>
 </ol> 
-<p><strong>If for any reason this automatic file creation doesn't work, don't worry. All this does is fill in the database information to a configuration file. You may also simply open <code>wp-config-sample.php</code> in a text editor, fill in your information, and save it as <code>wp-config.php</code>. </strong></p>
+<p><strong>If for any reason this automatic file creation doesn't work, don't worry. All this does is fill in the database information to a configuration file. You may also simply open <code>wp-config-sample.php</code> in a text editor, fill in your information, and save it as <code><php echo $conffile ?></code>. </strong></p>
 <p>In all likelihood, these items were supplied to you by your ISP. If you do not have this information, then you will need to contact them before you can continue. If you&#8217;re all ready, <a href="setup-config.php?step=1">let&#8217;s go</a>! </p>
 <?php
 	break;
@@ -120,7 +123,7 @@
 
     // We'll fail here if the values are no good.
     require_once('../wp-includes/wp-db.php');
-	$handle = fopen('../wp-config.php', 'w');
+	$handle = fopen('../'.$conffile, 'w');
 
     foreach ($configFile as $line_num => $line) {
         switch (substr($line,0,16)) {
@@ -144,7 +147,7 @@
         }
     }
     fclose($handle);
-	chmod('../wp-config.php', 0666);
+	chmod('../'.$conffile, 0666);
 ?> 
 <p>All right sparky! You've made it through this part of the installation. WordPress can now communicate with your database. If you are ready, time now to <a href="install.php">run the install!</a></p> 
 <?php
Index: wp-admin/install.php
===================================================================
--- wp-admin/install.php	(revision 3569)
+++ wp-admin/install.php	(working copy)
@@ -1,9 +1,12 @@
 <?php
 define('WP_INSTALLING', true);
-if (!file_exists('../wp-config.php')) 
-    die("There doesn't seem to be a <code>wp-config.php</code> file. I need this before we can get started. Need more help? <a href='http://wordpress.org/docs/faq/#wp-config'>We got it</a>. You can <a href='setup-config.php'>create a <code>wp-config.php</code> file through a web interface</a>, but this doesn't work for all server setups. The safest way is to manually create the file.");
+require_once('../wp-functions.php');
+$conffile = get_conf();
 
-require_once('../wp-config.php');
+if (!file_exists('../'$conffile)) 
+    die("There doesn't seem to be a <code>".$conffile."</code> file. I need this before we can get started. Need more help? <a href='http://wordpress.org/docs/faq/#wp-config'>We got it</a>. You can <a href='setup-config.php'>create a <code>".$conffile."</code> file through a web interface</a>, but this doesn't work for all server setups. The safest way is to manually create the file.");
+
+require_once('../'$conffile);
 require_once('./upgrade-functions.php');
 
 $schema = ( isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ) ? 'https://' : 'http://';
Index: wp-admin/link-parse-opml.php
===================================================================
--- wp-admin/link-parse-opml.php	(revision 3569)
+++ wp-admin/link-parse-opml.php	(working copy)
@@ -1,5 +1,7 @@
 <?php
-require_once('../wp-config.php');
+require_once('../wp-functions.php');
+$conffile = get_conf();
+require_once('../'$conffile);
 
 // columns we wish to find are:  link_url, link_name, link_target, link_description
 // we need to map XML attribute names to our columns
