Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-02-2007, 12:38 AM   PM User | #1
Bunyip
New to the CF scene

 
Join Date: Jan 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Bunyip is an unknown quantity at this point
Hosting multiple wesites in same webspace

Hi,

I have some webspace that I'm trying to use to host multiple websites - so I don't have to pay for additional hosting for each domain. I have 2 domain names that are pointing to the same webspace. I am a PHP novice, but did find some code that I have put in the index.php file that redirects to the appropriate site depending on what the user has typed in the address bar:

Code:
<?php
switch ($HTTP_HOST) {
    case "www.domain1.com":
        header("Location: http://www.domain1/folder1");
        break;
    case "www.domain2.com":
        header("Location: http://www.domain1/folder2");
        break;
} 
?>
The problem with this is that the user who has gone to www.domain2.com sees that they have been redirected to www.domain1/folder2.

Instead of a redirection, is there any way with a combination of PHP and frames that I can read what URL the user has typed in the address bar and display the relevant page, but masking that they are looking at a subfolder of a differen domain?

In other words, the user who types in www.domain2.com must still see www.domain2.com in the address bar, even though they are looking at www.domain1/folder2.

Thanks.
Bunyip is offline   Reply With Quote
Old 01-02-2007, 01:23 AM   PM User | #2
ess
Regular Coder

 
Join Date: Oct 2006
Location: United Kingdom
Posts: 865
Thanks: 7
Thanked 29 Times in 28 Posts
ess will become famous soon enough
Here two ways that you can do this....though, I am sure other people would have other solutions as well.

1- Use .htaccess file to create more than one domain. Just do a google search..and I am sure you will find some examples.
2- Control which contents you wish to serve by knowing which domain is in use. That is, you could use the switch statement you have...but without using a redirect. instead, set a variable to indicate which domain is in use...and hence, respond accordingly.

By the way, I would contact your hosting company and try and find out whether they could set different folders for you for each domain you own. That would be the best solution for this problem.

Good luck.
Ess
ess is offline   Reply With Quote
Old 01-02-2007, 03:05 AM   PM User | #3
Bunyip
New to the CF scene

 
Join Date: Jan 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Bunyip is an unknown quantity at this point
Quote:
Originally Posted by ess View Post
2- Control which contents you wish to serve by knowing which domain is in use. That is, you could use the switch statement you have...but without using a redirect. instead, set a variable to indicate which domain is in use...and hence, respond accordingly.
Thanks for your reply. This is the concept of what I was thinking of - use a frame in the index file to mask the source and use PHP to define the source of the frame contents.

The html in the index file for the frame would be something like this - a common technique for domain masking:

Code:
<_frameset_rows="100%,0" border="0">
<_frame_ src="http://www.domain1/folder2/index.html" frameborder="0">
<_frame_ frameborder="0">
< /frameset>
However, I will need to use a variable using PHP to define the frame source in the code above. If the user has www.domain1 in their address bar, the source will be www.domain1/folder2/index.html. If the user has www.domain2 in their address bar, the frame source will be www.domain1/folder1/index.html.

Please bear in mind I am a complete PHP novice, so I just need to know if this is possible and some help with the syntax for the PHP code.

Thanks.
Bunyip is offline   Reply With Quote
Old 01-02-2007, 03:49 AM   PM User | #4
Metroid48
New Coder

 
Join Date: Dec 2006
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Metroid48 is an unknown quantity at this point
I would agree with ESS in that you should contact your hosting company to see if they can set each domain name to a different folder. Or, you could use subdomains.
Metroid48 is offline   Reply With Quote
Old 01-02-2007, 05:57 AM   PM User | #5
Bunyip
New to the CF scene

 
Join Date: Jan 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Bunyip is an unknown quantity at this point
Quote:
Originally Posted by Metroid48 View Post
I would agree with ESS in that you should contact your hosting company to see if they can set each domain name to a different folder. Or, you could use subdomains.
I contacted my hosting company (ICDSoft) and unfortunately they say they can only 'park' any additional domains to my existing domain. In other words, www.domain2.com will only show the content of www.domain1.com - I cannot point it to different content without purchaing a new webhosting plan.

Maybe I need to look elsewhere. Can you suggest another host that supports PHP that would allow setting up different domains to point to a separate folder?
Bunyip is offline   Reply With Quote
Old 01-02-2007, 03:29 PM   PM User | #6
vinyl-junkie
$object->toCD-R(LP);


 
vinyl-junkie's Avatar
 
Join Date: Jun 2003
Posts: 3,053
Thanks: 2
Thanked 22 Times in 22 Posts
vinyl-junkie is on a distinguished road
My web host, A Small Orange, has what you're looking for. Here's what their website says:

Quote:
Can I host more than 1 domain, subdomain?

Yes, it is possible to host more than one domain on your account. To do this, go to CPanel (http://yoursite.com/cpanel) and log in.
For hosting multiple domains that go to the same site, use the Park Domain feature.
For hosting multiple domains that go to separate sites, use the Add-On Domain feature.
To make a subdomain (IE: http://subdomain.yoursite.com), use the subdomain feature.
Subdomains and add on domains will each be given their own folder. This folder will contain all the files for that name.
__________________
Music Around The World - Collecting tips, trade
and want lists, album reviews, & more
SNAP to it!
vinyl-junkie is offline   Reply With Quote
Old 01-02-2007, 08:28 PM   PM User | #7
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,452
Thanks: 0
Thanked 496 Times in 488 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
Bluehost allows you to put up to 6 domains on the one hosting space each in their own folder.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:15 AM.


Advertisement
Log in to turn off these ads.