Jump to content

Recommended Posts

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,

 

 

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/69679-subdomain-problem/
Share on other sites

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

 

Link to comment
https://forums.phpfreaks.com/topic/69679-subdomain-problem/#findComment-350175
Share on other sites

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 ?

Link to comment
https://forums.phpfreaks.com/topic/69679-subdomain-problem/#findComment-350195
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.