To accomplish this your host must support the use of domain aliases and your main site where your files are installed must be setup on a full domain name, not a sub domain.
Step 1:
Log in to your hosting control panel for your site and create some domain aliases to point to your first site. For example my main site is www.widgets.com and I setup www.blue-widgets.com and www.red-widgets.com as domain aliases.
Step 2:
Verify your domain alias works by visiting your alias domain. In our example if you visit www.red-widgets.com you should see the site contents of www.widgets.com
Step 3:
Replace the contents of your config.php file from the main site's ANS installation (/includes/config.php) with the code below:
- Code: Select all
<?php
switch ($_SERVER["SERVER_NAME"]) {
case 'www.blue-widgets.com':
define("dbhost", 'localhost');
define("dbuser", 'myuser');
define("dbpass", 'mypass');
define("dbname", 'bluewidget');
define("dbprefix", 'ans_');
break;
case 'www.red-widgets.com':
define("dbhost", 'localhost');
define("dbuser", 'myuser');
define("dbpass", 'mypass');
define("dbname", ''redwidget);
define("dbprefix", 'ans_');
break;
case 'www.green-widgets.com':
define("dbhost", 'localhost');
define("dbuser", 'myuser');
define("dbpass", 'mypass');
define("dbname", 'greenwidget');
define("dbprefix", 'ans_');
break;
default:
define("dbhost", 'localhost');
define("dbuser", 'myuser');
define("dbpass", 'mypass');
define("dbname", 'widget');
define("dbprefix", 'ans_');
}
Basically what this code does is checks the domain name of the page, if it matches any of the configured domains it will use a new database, if it does not match any of the domains it will use a default database which will be your main site.
To make things even simpler you could configure all the sites to share the same database by configuring each site use a different database prefix as below:
- Code: Select all
<?php
define("dbhost", 'localhost');
define("dbuser", 'myuser');
define("dbpass", 'mypass');
define("dbname", 'widget');
switch ($_SERVER["SERVER_NAME"]) {
case 'www.blue-widgets.com':
define("dbprefix", 'blue_');
break;
case 'www.red-widgets.com':
define("dbprefix", 'red_');
break;
case 'www.green-widgets.com':
define("dbprefix", 'green_');
break;
default:
define("dbprefix", 'ans_');
}
Step 4:
Upload your install folder and access each new site pointing to the install folder and install the site. Example http://www.blue-widgets.com/install/
This will install a new copy of ANS in your new database, completely seperate from the main site. If you use PhpMyAdmin or similar you could backup & restore your main database to the new databases manually to bypass the need to run the installer again.