[wp-hackers] Re: 2 URLs 1 WordPress install

R.J. Kaplan just.be.happy at gmail.com
Thu Aug 10 22:45:14 GMT 2006


I just put together a simple method, based on Francis' technique.

It's benefits are:
1. You only need to edit 3 lines in wp-config.php and do not need to  
add multiple config files.
2. All installations use the same database, with the prefix  
determined automatically.
3. Great for shared hosting plans, which limit the number of domains  
and databases, but allow domain pointing.

Unlike the other method, themes and plugins are shared, so this isn't  
suitable for different users wanting to share an installation, but  
it's really simple to set up if you're running multiple wordpress sites.

Here are the 3 lines of code:

$table_prefix = ereg_replace('^(www\.)', '', $_SERVER['HTTP_HOST']);
$table_prefix =  ereg_replace('\.', '', $table_prefix);
$table_prefix  = $table_prefix . '_';

The first line filters out www. from the beginning, so  
www.example.com and example.com use the same tables
the second line filters out the dots.
the third line combines it all with an underscore.

I wrote about it in my blog, the post can be found here: http:// 
me.mywebsight.ws/2006/08/11/host-multiple-wp-sites-on-one-installation/

Any feedback welcome.

~Joe

On Jul 28, 2006, at 5:35 PM, Francis Reyes wrote:

> I've written up my experiences on multiple wordpress blogs on a  
> single installation at http://ruckerz.oldbrownshoe.org/2006/07/28/ 
> multiple-wordpress-blogs-on-a-single-installation/
>
> Comments welcome.
>
> FR
>
>
>
> Dougal Campbell wrote:
>> Robert Deaton wrote:
>>> On 7/28/06, Mark Harwood <mark at phunky.co.uk> wrote:
>>>> Yes your right, its ONE site but with two domains - it already  
>>>> works in
>>>> a sense
>>>>
>>>> www.mem-gaming.co.uk/v2/
>>>> www.midnightevil.co.uk/v2/
>>>>
>>>> both go to the same site and pull the WordPress stuff, i was  
>>>> just in
>>>> need of sorting out the URL links. i think i will just remove  
>>>> the use of
>>>> bloginfo() for grabbing the URL out of the DB and instead just  
>>>> grab the
>>>> serveruri directly from the domain.
>>>
>>> A better and more reliable thing to do might be using a filter on
>>> bloginfo or the options to modify the domainname instead of removing
>>> them from the picture altogether.
>>>
>>
>> That's just what I was about to suggest -- hook into the  
>> 'bloginfo' filter, check against $_SERVER['HTTP_HOST'], and return  
>> different info as needed. Something like
>>
>>   function twoblogs($text) {
>>     $hostmap = array( 'host1.example.com' => 'host2.example.com',
>>       'Host One Blog' => 'Blog on Host Two');
>>
>>     if ($_SERVER['HTTP_HOST'] == 'host2.example.com') {
>>       $newtext = $hostmap['$text'];
>>       if (empty($newtext)) {
>>         $newtext = $text;
>>       }
>>     }
>>
>>     return $newtext;
>>    }
>>
>>   add_filter('bloginfo', 'twoblogs');
>>
>> In the $hostmap array, just put in mappings for whatever bloginfo  
>> strings should be different between the two hosts.
>>
>> Make sense?
>>
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers



More information about the wp-hackers mailing list