문제

Is it possible to to access web with url example.com but variables inside php (like SERVER_NAME) would act like sub.example.com?

We made wrong decision during development and now we are actually stuck with two separate versions of software. One for example.com and other for automatically generated subdomains. We could reserver one subdomain to act as our main domain, but we don't want that sub. example.com part.

도움이 되었습니까?

해결책

You should add some checks, for example:

function hasSubdomain($url) {
    $parsed = parse_url($url);
    $exploded = explode('.', $parsed["host"]);
    if(count($exploded) > 2){
       return true;
    }else{
       return false;
    }
}

if(!hasSubdomain($_SERVER['SERVER_NAME'])){
   $_SERVER['SERVER_NAME']="sub.example.com";
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top