Bunyip Posted January 2, 2007 Share Posted January 2, 2007 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]<?phpswitch ($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 Link to comment Share on other sites More sharing options...
trq Posted January 2, 2007 Share Posted January 2, 2007 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 Link to comment Share on other sites More sharing options...
corbin Posted January 2, 2007 Share Posted January 2, 2007 You could include the appropriate files.. Quote Link to comment Share on other sites More sharing options...
Bunyip Posted January 2, 2007 Author Share Posted January 2, 2007 [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. Quote Link to comment Share on other sites More sharing options...
SharkBait Posted January 2, 2007 Share Posted January 2, 2007 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 ;) Quote Link to comment Share on other sites More sharing options...
the_oliver Posted January 2, 2007 Share Posted January 2, 2007 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.