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