Page 1 of 1

Hosting multiple wesites in same webspace

Posted: Mon Jan 01, 2007 6:52 pm
by Bunyip
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: Select all

<?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 http://www.domain2.com sees that they have been redirected to http://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 http://www.domain2.com must still see http://www.domain2.com in the address bar, even though they are looking at http://www.domain1/folder2.

Thanks.

Posted: Mon Jan 01, 2007 7:07 pm
by WaldoMonster
There is no direct need to do this in PHP.
Almost all web servers can host multiple domains.
I have tested it with Apache and IIS.
Here is an example for Apache:

Code: Select all

NameVirtualHost *:80

<VirtualHost *:80>
    ServerName www.domain1.com
    ServerAlias domain1.com
    DocumentRoot "D:/Internet/domain1"
    CustomLog "D:/Internet/domain1.log" combined
</VirtualHost>

<VirtualHost *:80>
    ServerName www.domain2.com
    ServerAlias domain2.com
    DocumentRoot "D:/Internet/domain2"
    CustomLog "D:/Internet/domain2.log" combined
</VirtualHost>

Posted: Mon Jan 01, 2007 9:08 pm
by Bunyip
WaldoMonster wrote:There is no direct need to do this in PHP.
Almost all web servers can host multiple domains.
I have tested it with Apache and IIS.
Thanks for your reply.

Unfortunately I don't host my own web server so I am unable to configure Apache. What I was thinking of was to 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: Select all

<_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 http://www.domain1 in their address bar, the source will be http://www.domain1/folder2/index.html. If the user has http://www.domain2 in their address bar, the frame source will be http://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.

Posted: Mon Jan 01, 2007 10:17 pm
by nickvd
Talk to your host... the second you start framing your site, you will run into loads of problems...

Any competent host will be more than willing (and able) host setup things the way they're "supposed" to be setup (ala virtual hosting like waldo said).

If they refuse to assist you, I would suggest finding a new host.

Posted: Tue Jan 02, 2007 12:00 am
by Bunyip
nickvd wrote:Talk to your host... the second you start framing your site, you will run into loads of problems...

Any competent host will be more than willing (and able) host setup things the way they're "supposed" to be setup (ala virtual hosting like waldo said).

If they refuse to assist you, I would suggest finding a new host.
I contacted my hosting company (ICDSoft) and unfortunately they say they can only 'park' any additional domains to my existing domain. In other words, http://www.domain2.com will only show the content of http://www.domain1.com - I cannot point it to different content without purchaing a new webhosting plan.

Maybe I do 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?

Posted: Tue Jan 02, 2007 4:31 am
by Kieran Huggins
There's a web-host review thread on the forum already - lots of good advice there already.

Failing that, drop by "webhostingtalk" forums.