第一步是将子域名置于DNS主机服务器中。要做到这一点,你需要操纵dns文件。例如,如果你使用BIND作为DNS服务器,你可以打开保存你的DNS配置的文本文件,例如:“c:\ program files \ dns \ var \ mysite.com”,然后你添加一行为
subdomain.mysite.com. IN A 111.222.333.444
此外,您还可以更改文件的ID以向BIND发送消息以更新子域。
第二步是将新的子域重定向到正确的目录。您可以使用rewritepath
做的
protected void Application_BeginRequest(Object sender, EventArgs e)
上
Global.asax
protected void Application_BeginRequest(Object sender, EventArgs e)
{
if (HttpContext.Current.Request.Url.Host.StartsWith("subdomain."))
{
// here you need to find where to redirect him by reading the url
// and find the correct file.
HttpContext.Current.RewritePath("/subdomain/" + Request.Path, false);
}
// .... rest code
}
它不是那么容易,不是那么难......也许还有一些更小的问题,如写入权限DNS。你也需要知道DNS,阅读手册。