Views: 9917
Last Modified: 15.09.2014
Pseudomultisiting options implemented externally in different domains but actually supported by a single Apache server are technically possible (but not recommended). This configuration option makes it impossible to separate data by websites in the administrative part: forums, blogs, newsletters, etc. will be displayed together. In this case, the license for the second website is not required.
First Option
In this case, multisiting is implemented using the index page code of the main website.
The particularity of this method is that in case of improper address indications the content of one website may be displayed in the template of the other website.
Apache Server Set Up
The server setup procedure is similar to that of one domain multisiting setup.
Website Settings
Website setup procedure is similar to that of one domain multisiting setup with the only difference that own domain names should be indicated for each website in the Domain field.
Index Page Setup
Going to http://www.site1.com or http://www.site2.com, a visitor of either website actually goes to the page /index.php
, located in the catalog indicated in the parameter DocumentRoot of the web server settings. In the multiple site configuration, the role of this file changes slightly, and instead of contents of the index page of the root of either website a PHP code selecting a website depending on the current domain name should be located in this file.
The following functions of the CMainPage class can be used for this purpose:
An Example of the Index Page of the Portal when a website is determined using the current domain name:
<?
// we connect the file with the CMainPage class
require($_SERVER['DOCUMENT_ROOT']."/bitrix/modules/main/include/mainpage.php");
// we obtain the ID of the current website using the domain name
$site_id = CMainPage::GetSiteByHost();
// we obtain the absolute path to the index page of the website folder
$page = CMainPage::GetIncludeSitePage($site_id);
// if the website is determined and the index page is determined
if(strlen($site_id)>0 && strlen($page)>0)
{
// we connect the page
require_once($page);
}
else // otherwise, if the website is not determined
{
require($_SERVER['DOCUMENT_ROOT']."/bitrix/header.php");
// a code may be provided to be displayed if
// the website was not determined earlier
?>
<?require($_SERVER['DOCUMENT_ROOT']."/bitrix/footer.php");
}
?>
This code example determines the domain name used by a visitor with the help of the function CMainPage::GetSiteByHost, compares this domain name with the names stored in the website settings in the field Domain name in order to determine the website ID and connects the index page into the body of the document from the folder of the relevant website using the function CMainPage::GetIncludeSitePage.
In our example, it will mean that the page /s1/index.php
will be shown directly in the body of the current page without redirection to a visitor who came to the address http://www.site1.com. And the page /s2/index.php
– to a visitor who came to the address: http://www.site2.com.
This algorithm permits avoiding redirections for users and search bots and ensures convenient work with multisiting configuration. This algorithm is recommended but it is not the only one available for work with a multiple site version.
An Example of the Index Page of the Portal, when a website is determined using the languages set in the user’s browser:
<?
// we connect a CMainPage class file
require($_SERVER['DOCUMENT_ROOT']."/bitrix/modules/main/include/mainpage.php");
// obtain website ID by Accept-Language
$site_id = CMainPage::GetSiteByAcceptLanguage();
// if the website is determined
if(strlen($site_id)>0)
{
// we redirect to the index page of the website
CMainPage::RedirectToSite($site_id);
}
else // otherwise, if the website is not determined,
{
require($_SERVER['DOCUMENT_ROOT']."/bitrix/header.php");
// a code may be provided to be displayed if
// the website was not determined earlie
?>
<?require($_SERVER['DOCUMENT_ROOT']."/bitrix/footer.php");
}
?>
In this example of the code, the function CMainPage::GetSiteByAcceptLanguage checks which languages are set in the settings of the visitor’s browser, compares them with the language ID of the website, and returns the most suitable website.
Once the website is determined, the function CMainPage::RedirectToSite will perform redirection (web server response 302), and redirect the user to the index page of the folder of the indicated website, e.g. to http://www.site1.com/s1/ or http://www.site2.com/s2/.
An Example of the Index Page of the Portal, when one website is located in the root and others in folders, and at the same time the websites have the same hosts:
<?
// We connect a CMainPage class file
require($_SERVER['DOCUMENT_ROOT']."/bitrix/modules/main/include/mainpage.php");
// obtain website ID of the current website using the domain name
$mainpage_siteid = CMainPage::GetSiteByHost();
// if the current website is s2, we will obtain the absolute path to the index page of the website folder
if ($mainpage_siteid != "s1" && $page = CMainPage::GetIncludeSitePage($mainpage_siteid)):
// connect the page
require_once($page);
die();
endif;
require($_SERVER['DOCUMENT_ROOT']."/bitrix/header.php");
// then we can place a normal text of the index page,
// which will be connected when the website located in the root of is active
<?require($_SERVER['DOCUMENT_ROOT']."/bitrix/footer.php");
?>
In our example, if the "default" website (from websites’ settings) is s2, it is this website’s index page that will be displayed.
If your websites are in fact different international language mirrors, you can use the option of determining a website according to the languages installed in the visitor’s browser.
Second Option
If the two websites have different domains and designs and the same base is used for both websites (store’s settings, etc. are the same as well), the following option may be used.
Solution:
- Go to website’s settings (Control Panel > Settings > System settings > Websites > Websites)
- Set for the first template Condition type = PHP expression. Type the following as a condition:
strpos($_SERVER["HTTP_HOST"], 'domain1.com')!==false
- Set for the second template Condition type = PHP expression. Type the following as a condition:
strpos($_SERVER["HTTP_HOST"], 'domain2.com')!==false
- Write both domains in the field Domain.
The procedure for server set up is the same as that of a one-domain multisiting setup.