« Website integrationMultiple blogs »

Multiple blogs on multiple domains

Set up your webserver

If you are using shared hosting, check that your hosting plan allows multiple domains and set those up as "Domain Aliases".

If your are using a VPS or a dedicated server, make sure to set up your webserver so that all (sub-)domains map to the same DocumentRoot (as it's called in Apache). So accessing foo.example.com should go to the same DocumentRoot ("public_html" folder) as bar.example.com. Of course, you can also map www.otherdomain.com to the same place.

apache2.conf should include something like this:

 <VirtualHost *>
ServerName mydomain.com
ServerAlias *.mydomain.com
ServerAlias *otherdomain.com
UseCanonicalName Off
DocumentRoot /home/mydomain/www
DirectoryIndex index.html index_multi.php
</VirtualHost>

See also: Multi-domain test-environment

Set up your blogs

Go to Blog Settings > URLs and select "Absolute URL" as the "Blog Base URL". Set this to the full URL of your blog, e.g. http://myblog.example.com/. (Don't forget the trailing slash or you will get an error!)

Optionally Set up mod_rewrite

You have to create a .htaccess file (or append it to an existing one) in your blog root directory (e.g. .htaccess) with the following content:

# BEGIN QP
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END QP

This will redirect every request that is not an existing file or directory to /index.php, where Quam Plures will detect the requested blog out of the absolute URL.

If your blog is not located in the DocumentRoot of your webserver, you'll have to adjust "RewriteBase" and the path to "index.php" accordingly.

Cookies

If all your blogs are on a subdomain of a global domain ($baseurl), you don't need to adjust the cookie stuff.

Otherwise, in order to make your cookies, especially the SessionCookie, available across all your subdomains, you could explicitly set

$cookie_domain = '.example.com';

in /conf/_advanced.php.

If you are not using subdomains, but different domains, the following should work:

$cookie_domain = '.'.$_SERVER['HTTP_HOST'];

htsrv URL

The htsrv URL gets used (e.g. for posting comments or plugins use this) as callback (e.g. the captcha_img_plugin). Especially for AJAX callbacks it's important that the callback is to the same domain and uses the same protocol (http/https). With some firewalls this is also needed for images.

Therefore you should dynamically create the $htsrv_url variable (located in /conf/_advanced.php), e.g.:

$htsrv_url = ( (isset($_SERVER['HTTPS']) && ( $_SERVER['HTTPS'] != 'off' ) ) ?'https://':'http://').$_SERVER['HTTP_HOST'].'/htsrv/';