dongyinshua9996
dongyinshua9996
2014-03-09 02:03

如何将子域名屏蔽为域

已采纳

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.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • dousui4577 dousui4577 7年前

    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";
    }
    
    点赞 评论 复制链接分享

相关推荐