Multiple Domains on One Site

Using a single web hosting account to host multiple sites

Multiple Domains on One Site

Postby sublet » Mon Mar 12, 2007 8:50 am

I have a page that pulls up certain content based on the ID that is attached.

Like so :
www.domain.com/thisPage.php?ID=1234

I want to be able to set different domains to goto different ID#'s.

Like so :
www.domainOne.com -> www.domain.com/thisPage.php?ID=1234
www.domainTwo.com -> www.domain.com/thisPage.php?ID=5678

Any ideas?
sublet
 
Posts: 8
Joined: Thu Mar 30, 2006 10:35 am

Postby richardk » Mon Mar 12, 2007 2:35 pm

The domains need to go to the main domain's document root.

Are there a few domains? Then you can do this
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?domainA\.com$ [NC]
RewriteRule ^$ /thisPage.php?ID=1234 [QSA,L]

RewriteCond %{HTTP_HOST} ^(www\.)?domainB\.com$ [NC]
RewriteRule ^$ /thisPage.php?ID=5678 [QSA,L]


If there are lots of domains you will be better off adding an array to the beginning of the script
Code: Select all
<?php

$domainToId = array(
  'domainA.com' => 1234,
  'domainB.com' => 5678,
);

if(getenv('REDIRECT_MRDOM') !== false
   && array_key_exists(getenv('REDIRECT_MRDOM'), $domainToId))
{
  $_GET['ID'] = $domainToId[getenv('REDIRECT_MRDOM')];
}

with
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} !^(www\.)?domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+\.[^\.]+)$ [NC]
RewriteRule ^$ /thisPage.php [E=MRDOM:%2,QSA,L]


Or using a RewriteMap (only if you have access to the httpd.conf file).
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby sublet » Wed Apr 11, 2007 6:00 am

I actually do have access to the entire server. What is a rewrite map?
sublet
 
Posts: 8
Joined: Thu Mar 30, 2006 10:35 am

Postby richardk » Wed Apr 11, 2007 11:02 am

For a RewriteMap you'd have a text file (or you can use a program) on the server and it would have the domains and IDs in it, eg. (domain-to-id.map)
Code: Select all
domainA.com 123
domainB.com 456


Then in the httpd.conf file (in the <VirtualHost> for the document root)
Code: Select all
Options +FollowSymLinks

RewriteEngine On
RewriteMap domain2id txt:/path/to/domain-to-id.map

RewriteCond %{HTTP_HOST} ^(www\.)?(.+\..+)$ [NC]
RewriteCond ${domain2id:%2|notfound} !^notfound$ [NC]
RewriteRule ^/$ /thisPage.php?ID=${domain2id:%2} [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 20 guests

cron