How to overcome root domain CNAME restrictions?

前端 未结 8 765
失恋的感觉
失恋的感觉 2020-12-04 05:23

We are hosting many web applications for our customers. As is obvious they want to use their own domains to refer to those applications, usually they want that any user tha

相关标签:
8条回答
  • 2020-12-04 06:13

    You have to put a period at the end of the external domain so it doesn't think you mean customer1.mycompanydomain.com.localdomain;

    So just change:

    customer1.com IN CNAME customer1.mycompanydomain.com
    

    To

    customer1.com IN CNAME customer1.mycompanydomain.com.
    
    0 讨论(0)
  • 2020-12-04 06:20

    Thanks to both sipwiz and MrEvil. We developed a PHP script that will parse the URL that the user enters and paste www to the top of it. (e.g. if the customer enters kiragiannis.com, then it will redirect to www.kiragiannis.com). So our customer point their root (e.g. customer1.com to A record where our web redirector is) and then www CNAME to the real A record managed by us.

    Below the code in case you are interested for future us.

    <?php
    $url = strtolower($_SERVER["HTTP_HOST"]);
    
    if(strpos($url, "//") !== false) { // remove http://
      $url = substr($url, strpos($url, "//") + 2);
    }
    
    $urlPagePath = "";
    if(strpos($url, "/") !== false) { // store post-domain page path to append later
      $urlPagePath = substr($url, strpos($url, "/"));
      $url = substr($url, 0, strpos($url,"/"));
    }
    
    
    $urlLast = substr($url, strrpos($url, "."));
    $url = substr($url, 0, strrpos($url, "."));
    
    
    if(strpos($url, ".") !== false) { // get rid of subdomain(s)
      $url = substr($url, strrpos($url, ".") + 1);
    }
    
    
    $url = "http://www." . $url . $urlLast . $urlPagePath;
    
    header( "Location:{$url}");
    ?>
    
    0 讨论(0)
提交回复
热议问题