Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php redirect with 1 hosting account, 3 domains

Status
Not open for further replies.

frozenpeas

Technical User
Joined
Sep 13, 2001
Messages
893
Location
CA
Hi,

I have 3 domain names that point to my hosting provider. I would like to serve 3 different sites, while keeping the the url as 'normal' as possible.

I am using this right now:

Code:
<?
$refer = $HTTP_HOST;
// note: domain.com, [URL unfurl="true"]www.domain.com,[/URL] domain.net, [URL unfurl="true"]www.domain.net[/URL] will match
if (eregi(&quot;[URL unfurl="true"]www.domain1.com&quot;,[/URL] $refer)) { header (&quot;Location: ./domain1/&quot;); } 

elseif (eregi(&quot;[URL unfurl="true"]www.domain2.com&quot;,[/URL] $refer)) { header (&quot;Location: ./domain2/&quot;);}

elseif (eregi(&quot;[URL unfurl="true"]www.domain3.ca&quot;,[/URL] $refer)) { header (&quot;Location: ./domain3/&quot;);}
?>

This is okay but if you go to the url becomes This causes problems for me as I cannot access the site root as /images/spacer.gif... I now have to call /domain2/images/spacer.gif

Is there a better way to split up the 3 domains than what I am doing?

Thanks. frozenpeas
 
The method of choice would be to have the configuration of the web server handle all that.

If your provider uses Apache, check out if the mod_rewrite is available. You can use .htaccess files to rewrite the URLs.

Another trick is an HTML/PHP solution:
Create a <BASE href=&quot;yourdomain/path-to-new-root/&quot;> tag.
This will reference all document relative links with the specified starting point. You need to you use document relative links instead of root relative:
src = &quot;images/blah.gif&quot; rather than
src = &quot;/images/blah.gif&quot;

A document in a folder &quot;about&quot; would point to:
src=&quot;../images/blah.gif&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top