Jump to content

Hosting multiple wesites in same webspace


Bunyip

Recommended Posts

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;
}
?>[/code]
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.
[quote author=thorpe link=topic=120622.msg494965#msg494965 date=1167699621]
I dont think you can really do this with php, the request has already gone to far by this stage. You need to look into Apache's virtual hosts, but yeah, if your on a shared server its not going to happen.
[/quote]
Thanks for your reply. The concept of 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]<_frameset_rows="100%,0" border="0">
<_frame_ src="http://www.domain1/folder2/index.html" frameborder="0">
<_frame_ frameborder="0">
< /frameset>[/CODE]

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.
I think this will only work with Virutal Host with Apache's configuration.  It's easier anyway.

It's what I do, and I am sure alot of other web hosts do it as well.  I have 1 machine and multiple domains that point to it.

So I do something similar to this in Apache's httpd.conf file:
[code]
<VirtualHost *:80>
  Server www.blah.com
  Alias blah.com
  DocRoot /home/blah/public_html
</VirtualHost>
[/code]

Now the above isn't totally correct but you get the idea ;)
Virtual hosts would be far supirior!  What type of hosting are you on?

In theiory if both domain names point to the same file, you can display content determined by which address has been sent.... In theory! 
However it can get messy!  Why are you trying this? 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.