Powered by MediaWiki
Personal tools

MultipleDomains

From b2evolution manual

Revision as of 19:40, 1 March 2011 by BruceClement (Talk | contribs)
Jump to: navigation, search

Contents

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

URL-settings.jpg

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!)

(Additionally, in older b2evolution version, you should set "Prefered access type" to "Explicit reference to stub file" and delete the stub name. This way you will have a clean http://sub.domain.tld/ style for your Blog URLs.)

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. blogs/.htaccess) with the following content:

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

This will redirect every request that is not an existing file or directory to /index.php, where b2evolution 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.

If you are not using subdomains, but different domains, you will need to make this change to be able to log into any domains except the first one. Failing to set this correctly can be the cause of messages on the login form like
WARNING: you are trying to log in to http://example.com/ but your cookie domain is .example.net. You will not be able to successfully log in to the requested domain until you fix your cookie domain in your b2evolution configuration.

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/';