Wordpress: How to use one installation for multiple Domains

wp-20-button-trans Wordpress: How to use one installation for multiple DomainsWhen it comes to an open source blogging software, Wordpress builds the ultimative tool for me. If you get used to Wordpress you will love it and use it at other projects as well. I have 7 wordpress sites und it gets difficult to keep all of them updated, since so many new features get out everytime. The best way to keep track of all wordpress sites would be Wordpress MU, but it is kind of to big scaled for most of us. Now, which other solutions may help? I found a note by lunabyte in the wordpress forums how to use the standard Wordpress installation with multiple Domains. I hope you will enjoy it and report your experiences with it.

If you have worked out your own idea, please please keep us informed so we can improve this knowte by lunabyte to an a-class how-to!

Lunabyte: 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…


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.


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.


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.

Share the love

Spread this KnowTe

Digg Del.icio.us Stumble Float Technorati Bump
Whatever you want to say!

Apr 21, 2010
No: 12 / ID: 6026

I think you will hava problems during upgrade cause you will upgrade the source in one shot, but you have to upgrade all the tables with the differet prefix in different times.

Feb 26, 2010
No: 11 / ID: 5704

You cannot believe how long ive been googling for something like this. Browsed through 9 pages of Google results and couldnt find anything. First page of bing. There you are!…. Gotta start using that more often

Dec 31, 2009
No: 10 / ID: 5445

Fred is right, this is way to general, it’s written like a children playbook and not a php explanation.

Jun 09, 2009
No: 9 / ID: 4357

Thought this may be the case, thanks for posting and I’ll update how it goes!

Oct 01, 2008
No: 8 / ID: 2755

Thank you very much. Maybe you can help us to extract the cite and make it more understandable for others.

Sep 30, 2008
No: 7 / ID: 2754

Despite the other commenters I found this very helpful :)

Sep 11, 2008
No: 6 / ID: 2568

Did you use Wordpress MU? The second way you mentioned should work very well.

Sep 11, 2008
No: 5 / ID: 2564

I have several subdomains on my domain, and I figured I give it a shot. After 4 hours I abandoned (for now) since I couldn’t figure out why my wp-config.php file would not be read by the sub-domain installation. I guess It only works if you have several domain names, but not if you have a main domain name and later 3 sub domains.
Maybe I’ll give it another shot later…

Jul 28, 2008
No: 4 / ID: 1309

Hey Cory. Thanks for your help. We have tried to point out the main idea of this tutorial by “lunabyte”. Since he/she has written and worked on this, we can’t follow his/her steps into it. Sebastian just found it useful for some people who are looking for solutions and like to save time for research on this.

If you have worked on an own idea and found a way, please tell us how you did it, and we will work over this knowte and make a 1.class how-to. There would be also a guest-post possible and a promotion to thousands of readers if you like.

Jul 27, 2008
No: 3 / ID: 1255

Hi Knowtebook, I would probably not be as harsh as Fred, but I do agree that a how-to article should be easier to follow. To do this, I would spell out each step “Step 1, Step 2. etc” and put space between each step so they are clearly separated and readable.

Also, I would use a different font, or at least not italicize it as that affects readability big time.

Otherwise, fantastic content, keep it up!

Jul 24, 2008
No: 2 / ID: 1091

Hey Fred. Thanks for your reply. What are you experiences with it and what should be added to this post? Please help us to satisfy your needs. If you dislike it, please tell us to improve, too.

Jul 23, 2008
No: 1 / ID: 1072

This is so POOOOOOOOOOOOOOOOOOOORLY explained…”the right place, redirected there, moved here” you use way too general terms to keep it simple for yourself to explain and impossible for others to understand. Sorry bro…mod_rewrite it up!!

Leave a comment!
Note: You can also use your free Gravatar avatar on Knowtebook! Please also read our Publishing Policy before posting.