MultipleDomains
From B2evolution
Contents |
[edit] Set up your webserver
The webserver should be setup to map all (sub-)domains 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. (Note: you could even map otherdomain.com to the same place.)
apache2.conf should include something like this:
<VirtualHost *>
ServerName mydomain.com
ServerAlias *.mydomain.com
UseCanonicalName Off
DocumentRoot /home/mydomain/www
DirectoryIndex index.html index_multi.php
</VirtualHost>
See also: Multi-domain test-environment
[edit] Set up your blogs
Go to the Blogs tab and in the "Access parameters" fieldset choose "Absolute URL" as "Blog Folder 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 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.
[edit] 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.
[edit] 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'];
[edit] 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, e.g.:
$htsrv_url = ( (isset($_SERVER['HTTPS']) && ( $_SERVER['HTTPS'] != 'off' ) ) ?'https://':'http://').$_SERVER['HTTP_HOST'].'/htsrv/';

