如何克服根域CNAME限制? [英] How to overcome root domain CNAME restrictions?

查看:247
本文介绍了如何克服根域CNAME限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在为我们的客户托管许多网络应用程序。很明显,他们希望使用自己的域来引用这些应用程序,通常他们希望任何用户键入 http:// www.customer1.com http://customer1.com 转到他们的网络应用程序。



我们正在面对的情况是,我们需要在不久的将来灵活地更改IP地址。而且我们不想依靠客户在他们的域上进行A记录更改。所以我们认为使用CNAMES将会起作用,但是我们发现CNAME不适用于根域。



基本上:

  customer1.com IN CNAME customer1.mycompanydomain。 com //这是无效的作为RFC 
www.customer1.com IN CNAME customer1.mycompanydomain.com //这是有效的,将工作

我们希望能够更改customer1.mycompanydomain.com或A记录的IP地址,我们的客户将遵循我们控制的记录。



在我们的DNS中将看起来像:

  customer1.mycompanydomain.com IN A 5.5 


解决方案

感谢sipwiz和MrEvil。我们开发了一个PHP脚本,它将解析用户输入的URL,并将 www 粘贴到其顶部。 (例如,如果客户输入 kiragiannis.com ,那么它将重定向到 www.kiragiannis.com )。因此,我们的客户将其根(例如 customer1.com 指向 A 记录我们的网络重定向器),然后 www CNAME 到我们管理的真实 A 记录。 p>

下面的代码,以防您对未来感兴趣。

 <?php 
$ url = strtolower($ _ SERVER [HTTP_HOST]);

if(strpos($ url,//)!== false){//删除http://
$ url = substr($ url,strpos($ url, //)+ 2);
}

$ urlPagePath =;
if(strpos($ url,/)!== false){//存储后域页面路径以追加
$ 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){//摆脱子域
$ url = substr($ url, strrpos($ url,。)+ 1);
}


$ url =http:// www。 。 $ url。 $ urlLast。 $ urlPagePath;

header(Location:{$ url});
?>


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 that either type http://www.customer1.com or http://customer1.com goes to their web application.

The situation we are facing is that we need to have the flexibility to change IP addresses in the near future. And we don't want to rely on the customer doing the A record change on their domains. So we thought that using CNAMES will work, but as we find out CNAMEs will not work for the root domain.

Basically:

customer1.com IN CNAME customer1.mycompanydomain.com //this is invalid as the RFC
www.customer1.com IN CNAME customer1.mycompanydomain.com //this is valid and will work

We want to be able to change the IP address of customer1.mycompanydomain.com or the A record and our customers will follow this record which we have control over.

in our DNS it will look like:

customer1.mycompanydomain.com IN A 5.5.5.1

any ideas?

解决方案

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}");
?>

这篇关于如何克服根域CNAME限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆