Well, well well.
I started messing around a couple hours ago with this.
In short: It works, beautifully.
I’ll try to keep this as short as possible.
Here’s what I did.
The set-up:
I used three domains for this experiment. We’ll say md1.tld, md2.tld, and md3.tld.
All three domains point to the root public html directory.
The process:
1) Installed wordpress.
WordPress extracts to a “wordpress” directory. I didn’t feel like moving all the files up a level, so I simply renamed the directory to another name (I used “media”, but whatever), and then moved the index.php file up a level. I have other stuff in the main directory, else I could have just did an mv, and made it the new root html dir. Anyway, for testing this worked out nice since it is different than a completely untouched install.
I did the modification to index.php, to point it to the right place, and put a new index.php in the directory with all the core files that redirect to the one above.
Next, I added the info to config.php, and installed as normal.
I made a few minor changes to the default configuration in the admin panel, as I usually tend to do. These included:
– changed site name to suit the purpose, and description,
– as well as took out pingomatic (no need to ping with test posts),
– as well as changed the permalinks to “/%category%/%postname%.html.
I left the theme set on Kubrick, but I did upload another theme to use later.
Changed my password. (important)
Edited the default hello world, and comment. Left them, just changed the data. Did same for default “about” page too.
Back into phpmyadmin, I edited the user table, and replaced the value “admin” in login and nicename to something different.
Now that I have a workable default configuration, onto step 2.
2) Dumped the current tables
PhpMyAdmin, dumped the tables, saved them in a default local file.
Made a copy, renamed it to Dump-md2, and then did a search/replace to find the original domain and replace it with the new one.
Next, did a search for the original table prefix (i used “md1___”) and replaced it with the new table prefix (“md2___”).
Next, pasted it back into phpmyadmin, and it created just fine.
3) Time to alter the config.
Opened config.php to make the following changes. I will generalize them here, but you’ll get the idea.
– above the db info, i added a 4 sequence if/elseif statement.
I used 2 stristr functions, and checked the $_SERVER variables
HTTP_HOST, and X_FORWARDED_HOST for “md1.tld”.
If it returns true, I set a variable to equal the table prefix for md1
( $tbl_xtest = md1___ )
Then added two elseif statements to the sequence, changed the domain i was looking for, and the resulting table prefix.
The final check in the sequence was a plain old else, which set the table prefix variable to the one i wanted as a default. I used the first one.
Next, the line where it actually sets the table prefix, I removed ‘wp_’ and replaced it with $tbl_xtest.
4) Testing
I uploaded the new config file, and checked the initial domain. Check 1.
I checked the second domain. It worked flawlessly. The third was just fine too.
Now, time to see what happens if I use a domain not listed. Bam. It was the default site, just as it should be.
I logged into the second site, and made a few changes. (Note, with the duplicated tables, your username/pass is the same.)
I changed the theme to the one uploaded earlier, and some other things. All were seamless. It was no different than it being two installs.
In summary, it worked just fine.
Now for some notes…
Plugins.
Some may or may not work. In theory, most should. Ones that would not, are ones that create tables in the DB, but don’t use the table prefix. I’ve seen a couple that have done this, at least they did at the point I used them.
wp-cache? Don’t know, don’t use it.
Themes should be ok. As long as it keeps in line with table prefixes, and the site url/file settings, all should be ok. Don’t take my word for it though, as I said, I haven’t tested any plugins.
There might be an issue with plugins that want to modify the htaccess file. Look at what it wants to do, and edit it manually to be safe.
There shouldn’t be a problem with multiple conditions for different domains, but you never know.
Themes:
Should be fine. Since they are activated in each DB, and follow the settings that are set in the options pages.
I should note, that any theme customization for a particular domain should be made into a theme identifiable for that domain. I wouldn’t recommend allowing the theme files to be writable, just in case.
Permalinks:
Since they are controlled by the database, all is well.
Final Note:
This was a test, simply to prove that it can be done. I’m not supporting my changes, only showing you how. This is by far not an option for a novice or noob, that can barely figure out where to edit the style sheet for Kubrick to change the color of the links or header image.
If you don’t know php, and that does not mean being able to cut and paste a tag it means KNOW php, then don’t try this at home folks.
If you have a test site, then feel free to experiment until your hearts content.
Just remeber, I’m not responsible for anyone messing something up, and all that jazz. ??
Have fun.