zuzurelu Posted September 17, 2007 Share Posted September 17, 2007 Hi folks, I have a domain hosted on some provider (so I cannot configure apache myself ) and I create a subdomain, phisycally located under the same root like that : mydomain.com_root --------------- images/ --------------- includes/ ----------------------- style.css ----------------------- meta.php ----------------------- javascript.php --------------- one/ ------------------- index.php --------------- two --------------- three --------------- sub-domain/ -------------------------- index.php So my users ca now point to www.sub-domain.mydomain.com. The problem is I need when pointed to this sub domain, just display some page from MAIN domain as is. Of course that can be done with redirect but I need to display contents of < one/index.php > at subdomain, not redirected. I tried with include, like that : include ("../one/index.php"); but all the file referenced in /one/index.php needs now to be referenced one level up ../ and if thats ok for php, html seems to don't like ( I cannot reference CSS and image file like ../include/style.css ). Is there any sollution to display page pointed by /one/index.php directlly in subdomain, without modify originally file ? Or any other way to do it. Thanks in advance, Quote Link to comment https://forums.phpfreaks.com/topic/69679-subdomain-problem/ Share on other sites More sharing options...
freakstyle Posted September 17, 2007 Share Posted September 17, 2007 Hi There, sounds like you just need to pull in a specific file located under each subdomain. what you can do is in your main index page, find out what sub domain the user is on, then use that var to include the correct file. ex: <?php /* convert server string to an array, first element would be the subdomain */ $Host = explode('.',$_SERVER['HTTP_HOST']) ; /* make sure we've got a subdomain */ if ( isset($Host[0]) ) : /* we have one, so lets use it here to pull in that folders index file */ include_once $_SERVER['DOCUMENT_ROOT'] . '/' . $Host . '/index.php' ; endif; ?> good luck Quote Link to comment https://forums.phpfreaks.com/topic/69679-subdomain-problem/#findComment-350175 Share on other sites More sharing options...
rarebit Posted September 17, 2007 Share Posted September 17, 2007 I generally have a 'config.php' file with common vars in, have another var which is a prefix... no need to waste time checking if you know what it'll always be! Quote Link to comment https://forums.phpfreaks.com/topic/69679-subdomain-problem/#findComment-350179 Share on other sites More sharing options...
zuzurelu Posted September 17, 2007 Author Share Posted September 17, 2007 thanks freakstyle I still have to modify main domain scripts (all includes, images, readdir, etc), but at least works great, thanks ! $subdomain = explode('.',$_SERVER['HTTP_HOST']); $rootpath = str_replace($subdomain[0],'',$_SERVER['DOCUMENT_ROOT']); echo $rootpath; // for testing from inside sub-domain... work great ! echo "<img src=\"".$rootpath."images/logo.gif\">"; For leave domain script as is it's possible to write some htaccess script to solve the problem ? Quote Link to comment https://forums.phpfreaks.com/topic/69679-subdomain-problem/#findComment-350195 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.