[TUTORIAL] Multiple blogs with one WP codebase

vloza

Registered Member
Joined
Apr 7, 2010
Messages
74
Reaction score
49
Hi i decided to write this simple tutorial on how you can get multiple blogs with only one wordpress codebase without using WP MU. I use this method all the time in shared hosting (Godaddy, Hostgator, etc) with great results.

Remember it's not the recomended way, but it works for me.

Ok first thing is install wordpress, you can install it in the root directory or in any
subdir is the same.

Then edit the wp-config.php file to look like this

Code:
<?php
$host = $_SERVER['HTTP_HOST']; /* Get current domain */
$parts = explode('.',$host); /* Break domain */

if ($parts[3] = "") {  /* if domain starts with www */
    $domain = $parts[0]; 
} else { /* else */
    $domain = $parts[1];
}

switch ($domain) {
case "domain1":
    $db = "domain1db"; /* Set the db for this domain */
    $username="domain1user"; /* Set the user for this domain */
    $pass="domain1pass"; /* Set the pass for this domain */
    $host="domain1host"; /* Set the db host for this domain */
    $table_prefix  = 'domain1prefix_'; /* Set the table prefix for this domain */
    break;
case "domain2": /* etc */
    $db = "domain2db";
    $username="domain2user";
    $pass="domain2pass";
    $host="domain2host";
    $table_prefix  = 'domain2prefix_';
    break;
case "domain3":
    $db = "domain3db";
    $username="domain3user";
    $pass="domain3pass";
    $host="domain3host";
    $table_prefix  = 'domain3prefix_';
    break;    
}

define('DB_NAME', $db);    
define('DB_USER', $username);     
define('DB_PASSWORD', $pass); 
define('DB_HOST', $host); 

/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');

/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');

define('AUTH_KEY', 'put your unique phrase here');
define('SECURE_AUTH_KEY', 'put your unique phrase here');
define('LOGGED_IN_KEY', 'put your unique phrase here');
define('NONCE_KEY', 'put your unique phrase here');

define ('WPLANG', '');

if ( !defined('ABSPATH') )
	define('ABSPATH', dirname(__FILE__) . '/');

require_once(ABSPATH . 'wp-settings.php');
?>

What we did is, check for the domain (you can change the code to check for subdomain,directories, etc) and for each domain set the corresponding values for db, user, pass, etc.

Now for the sitemap and robots you need plugins that works virtually (don't generate real files) for this i use these plugins

Code:
-Sitemap Index
wordpress.org/extend/plugins/sitemap-index/

-KB robots.txt
wordpress.org/extend/plugins/kb-robotstxt/


now you need to edit the .htaccess, mine looks like this
***REMOVE THE UNDERSCORES***

Code:
<IfModule mod_rewrite.c>
RewriteRule ^sitemap\.xml /wp-content/plugins/sitemap-index/gen_sitemap.php?s=0 [L]
RewriteCond %{HTTP_HOST} !^$ [NC]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(.*)$ [NC]
#uncomment this and remove underscores
#RewriteRule ^(.*)$ "h_t_t_p_:_/_/_w_w_w.%1/$1" [L,R=301]
</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

The htacces rules are simple, if sitemap.xml is requested then redirect to the plugin file, if domain without www is requested redirect to www version, you can modify those rules as you want.

robots.txt works out of the box.

as a bonus i put my robots.txt content, you can use this in the plugin configuration screen.

Code:
User-agent: *
Disallow: /cgi-bin/
Disallow: /wp-admin/
Disallow: /wp-includes/
Disallow: /wp-content/plugins/
Disallow: /wp-content/themes/

Disallow: /?s=
Disallow: /feed
Disallow: /comments/feed
Allow: /feed/$
Disallow: /*/feed/$
Disallow: /*/feed/rss/$
Disallow: /*/trackback/$
Disallow: /*/*/feed/$
Disallow: /*/*/feed/rss/$
Disallow: /*/*/trackback/$
Disallow: /*/*/*/feed/$
Disallow: /*/*/*/feed/rss/$
Disallow: /*/*/*/trackback/$

#disallow some crawlers
User-agent: Black Hole
Disallow: /

User-agent: Titan
Disallow: /

User-agent: WebStripper
Disallow: /

User-agent: NetMechanic
Disallow: /

User-agent: CherryPicker
Disallow: /

User-agent: EmailCollector
Disallow: /

User-agent: EmailSiphon
Disallow: /

User-agent: WebBandit
Disallow: /

User-agent: EmailWolf
Disallow: /

User-agent: ExtractorPro
Disallow: /

User-agent: CopyRightCheck
Disallow: /

User-agent: Crescent
Disallow: /

User-agent: Wget
Disallow: /

User-agent: SiteSnagger
Disallow: /

User-agent: ProWebWalker
Disallow: /

User-agent: CheeseBot
Disallow: /

User-agent: Alexibot
Disallow: /

User-agent: Teleport
Disallow: /

User-agent: TeleportPro
Disallow: /

User-agent: MIIxpc
Disallow: /

User-agent: Telesoft
Disallow: /

User-agent: Website Quester
Disallow: /

User-agent: WebZip
Disallow: /

User-agent: moget/2.1
Disallow: /

User-agent: WebZip/4.0
Disallow: /

User-agent: WebSauger
Disallow: /

User-agent: WebCopier
Disallow: /

User-agent: NetAnts
Disallow: /

User-agent: Mister PiX
Disallow: /

User-agent: WebAuto
Disallow: /

User-agent: TheNomad
Disallow: /

User-agent: WWW-Collector-E
Disallow: /

User-agent: RMA
Disallow: /

User-agent: libWeb/clsHTTP
Disallow: /

User-agent: asterias
Disallow: /

User-agent: httplib
Disallow: /

User-agent: turingos
Disallow: /

User-agent: spanner
Disallow: /

User-agent: InfoNaviRobot
Disallow: /

User-agent: Harvest/1.5
Disallow: /

User-agent: Bullseye/1.0
Disallow: /

User-agent: Mozilla/4.0 (compatible; BullsEye; Windows 95)
Disallow: /

User-agent: Crescent Internet ToolPak HTTP OLE Control v.1.0
Disallow: /

User-agent: CherryPickerSE/1.0
Disallow: /

User-agent: CherryPickerElite/1.0
Disallow: /

User-agent: WebBandit/3.50
Disallow: /

User-agent: NICErsPRO
Disallow: /

User-agent: Microsoft URL Control - 5.01.4511
Disallow: /

User-agent: DittoSpyder
Disallow: /

User-agent: Foobot
Disallow: /

User-agent: WebmasterWorldForumBot
Disallow: /

User-agent: SpankBot
Disallow: /

User-agent: BotALot
Disallow: /

User-agent: lwp-trivial/1.34
Disallow: /

User-agent: lwp-trivial
Disallow: /

User-agent: Wget/1.6
Disallow: /

User-agent: BunnySlippers
Disallow: /

User-agent: Microsoft URL Control - 6.00.8169
Disallow: /

User-agent: URLy Warning
Disallow: /

User-agent: Wget/1.5.3
Disallow: /

User-agent: LinkWalker
Disallow: /

User-agent: cosmos
Disallow: /

User-agent: moget
Disallow: /

User-agent: hloader
Disallow: /

User-agent: humanlinks
Disallow: /

User-agent: LinkextractorPro
Disallow: /

User-agent: Offline Explorer
Disallow: /

User-agent: Mata Hari
Disallow: /

User-agent: LexiBot
Disallow: /

User-agent: Web Image Collector
Disallow: /

User-agent: The Intraformant
Disallow: /

User-agent: True_Robot/1.0
Disallow: /

User-agent: True_Robot
Disallow: /

User-agent: BlowFish/1.0
Disallow: /

User-agent: JennyBot
Disallow: /

User-agent: MIIxpc/4.2
Disallow: /

User-agent: BuiltBotTough
Disallow: /

User-agent: ProPowerBot/2.14
Disallow: /

User-agent: BackDoorBot/1.0
Disallow: /

User-agent: toCrawl/UrlDispatcher
Disallow: /

User-agent: WebEnhancer
Disallow: /

User-agent: TightTwatBot
Disallow: /

User-agent: suzuran
Disallow: /

User-agent: VCI WebViewer VCI WebViewer Win32
Disallow: /

User-agent: VCI
Disallow: /

User-agent: Szukacz/1.4
Disallow: /

User-agent: QueryN Metasearch
Disallow: /

User-agent: Openfind data gathere
Disallow: /

User-agent: Openfind
Disallow: /

User-agent: Xenu\'s Link Sleuth 1.1c
Disallow: /

User-agent: Xenu\'s
Disallow: /

User-agent: Zeus
Disallow: /

User-agent: RepoMonkey Bait & Tackle/v1.01
Disallow: /

User-agent: RepoMonkey
Disallow: /

User-agent: Zeus 32297 Webster Pro V2.9 Win32
Disallow: /

User-agent: Webster Pro
Disallow: /

User-agent: EroCrawler
Disallow: /

User-agent: LinkScan/8.1a Unix
Disallow: /

User-agent: Keyword Density/0.9
Disallow: /

User-agent: Kenjin Spider
Disallow: /

User-agent: Cegbfeieh
Disallow: /

User-agent: SurveyBot
Disallow: /
#END - disallow some crawlers

And that's it , now you can have as many blogs as you want with only one wordpress codebase.

You can update, install plugins , etc in each one without breaking anything.
 
Why would anyone want to go through all this instead of just using MU?
 
are some one here implement this trick like OP said?
 
Easy

- Older WP MU was not compatible with Wordpress plugins.
- The newer WP (MU merged) is for subdomains/subdirectories (You can map domains with a plugin though).
- WP MU has a different structure than a normal wordpress.

This way you have the best of wordpress plugin/theme compatibility with only one codebase.
 
Why would anyone want to go through all this instead of just using MU?

I was just thinking the same and now MU is actually already implemented in to the standard WordPress install so whenever you want to make additional blogs on your blog you just enable something called WordPress Multisite in your Wordpress install.

Read more about WordPress Multsite here: http://codex.wordpress.org/Create_A_Network


Anyways: Must have taken the OP some time to put together the post so thanks for taking the time man. Much appreciated.
 
Yes i know about Wordpress MultiSite, i use that configuration for a network of blogs i have, but my post was oriented to a different situation.

First, wordpress multisite doesn't works with different domains out of the box it works with subdomains / subdirectory structures. To work with different domains it needs a plugin.

Second the structure of wordpress multisite has another level of security the superadmin or whatever it's called. So you have

-Superadmin
---Admin
------Readers, etc

To my knowledge you cannot tweak your db settings, for example one db for each blog or different table prefixes for blogs.

I'm not saying that my configuration is easy nor recommended :) but sometimes you'll need it. Also is more oriented to programmers not to users.

I use it for shared hostings if i want to move one of my blog all i need to do is backup the DB or tables with specific prefix upload the backup to the new host tweak the wp-config and you have your blog running.
 
Back
Top