我想创建一个允许我的用户拥有自定义域的功能。就像博主/wordpress 正在做的那样。
例如
http://www.domain.com
用户可以拥有自己的自定义域
http://www.custom.com
其中输入 www.custom.com 映射到 www.domain.com
我该怎么做?我正在使用 php。这是服务器配置吗?
我用我的多账户平台来做到这一点。每次他们指定域名时,我都会使用 cpanel api 创建一个附加域,并要求他们将其域上的名称服务器更改为我的主机。所以这里有一个例子: www.example.com ask user to change nameservers to ns1.hostingwerks.com and ns2.hostingwerks.com prompt user for their domain use api to add on their domain 告诉用户它已经完成,但要留出一些时间propigate 这需要你有 whm 访问权限,但它可能会给你一些帮助。
if(!empty($domain) AND $olddomain != $domain){
$d = explode(".",$origdomain);
if(count($d) != 1){
if($d[0] == "www" OR $d[0] == "http://www" OR $d[0] == "https://www"){
$origdomain = $d[1] .".". $d[2];
}
else {
$origdomain = $d[0] .".". $d[1];
}
}
if(substr($origdomain, 0, 8) == "https://"){
$origdomain = substr($origdomain, 8);
}
elseif(substr($origdomain, 0, 7) == "http://"){
$origdomain = substr($origdomain, 7);
}
$dom = $origdomain;
$user = "your cpanel client username";
$addonpass = "your new domain's password";
$cpanel_skin = "x3";
$passw = "your cpanel password";
$ownername = "your cpanel hosting user name";
$pass = "your cpanel password";
$host = "localhost";
//Using 'explode' breaks the domain into its constituent pieces, the name and the extension (TLD), and puts them in an array
$domai = explode('.',$dom);
/*the directory path is defined by the first element appended to public_html. It does not matter where this file, 'addonhelper.php', is located -
the program will always install the addon domains to this directory. If this needs to be changed, this line needs to be updated.
Some versions of Cpanel do not allow for this to be changed and will ignore changes. Most notably - version X.*/
$dir="public_html/sys";
//the user is the first element of the $domain, as requested
$user=trim($domai[0]);
//put the domain back together and trim whitespace.
$dom=trim($domai[0]).".".trim($domai[1]);
//create the cpanel request.
$request = "/frontend/$cpanel_skin/addon/doadddomain.html?domain=$dom&user=$user&dir=$dir&pass=$addonpass";
//process the request with addondomain below
$sock = @fsockopen($host,2082);
if(!$sock) {
print('Socket error');
exit();
}
//authenticate the connection
$authstr = "$ownername:$passw";
//make the passphrase slightly more difficult to decipher
$pass = base64_encode($authstr);
$in = "GET $request\r\n";
$in .= "HTTP/1.0\r\n";
$in .= "Host:$host\r\n";
$in .= "Authorization: Basic $pass\r\n";
$in .= "\r\n";
//process
fputs($sock, $in);
while (!feof($sock)) {
$result .= fgets ($sock,128);
}
fclose( $sock );
您需要更改新站点的 DNS 才能转发到他们的站点。
如果您只是想更改单个域,请将其上的名称服务器更改为相同,并将其设置为 plesk/cpanel 中的附加组件到同一文件夹。或者您可以转发域并将其屏蔽。这也有效。http://support.godaddy.com/help/article/422/forwarding-or-masking-your-domain-name