1、net 二级域名绑定子目录如何实现
要实现这个功能,首先要做域名泛解析,去域名管理里面的域名解析中添加一个:*.worldbao.com 指向服务器ip。
第二,重写URLRewrite里面的两个方法。
1.BaseMoleRewriter.cs 里面的BaseMoleRewriter_AuthorizeRequest方法
将
[c-sharp] view plaincopy
protected virtual void BaseMoleRewriter_AuthorizeRequest(object sender, EventArgs e)
{
HttpApplication app = (HttpApplication) sender;
Rewrite(app.Request.Path, app);
}
[c-sharp] view plaincopy
protected virtual void BaseMoleRewriter_AuthorizeRequest(object sender, EventArgs e)
{
HttpApplication app = (HttpApplication) sender;
Rewrite(app.Request.Path, app);
}
改为
[c-sharp] view plaincopy
protected virtual void BaseMoleRewriter_AuthorizeRequest(object sender, EventArgs e)
{
HttpApplication app = (HttpApplication) sender;
Rewrite(app.Request.Url.AbsoluteUri, app);
}
[c-sharp] view plaincopy
protected virtual void BaseMoleRewriter_AuthorizeRequest(object sender, EventArgs e)
{
HttpApplication app = (HttpApplication) sender;
Rewrite(app.Request.Url.AbsoluteUri, app);
}
2, MoleRewriter.cs 里面的 Rewrite 方法
将
[c-sharp] view plaincopy
protected override void Rewrite(string requestedPath, System.Web.HttpApplication app)
{
// log information to the Trace object.
app.Context.Trace.Write("MoleRewriter", "Entering MoleRewriter");
// get the configuration rules
RewriterRuleCollection rules = RewriterConfiguration.GetConfig().Rules;
// iterate through each rule...
for(int i = 0; i < rules.Count; i++)
{
// get the pattern to look for, and Resolve the Url (convert ~ into the appropriate directory)
string lookFor = "^" + RewriterUtils.ResolveUrl(app.Context.Request.ApplicationPath, rules[i].LookFor) + "$";
// Create a regex (note that IgnoreCase is set...)
Regex re = new Regex(lookFor, RegexOptions.IgnoreCase);
// See if a match is found
if (re.IsMatch(requestedPath))
{
// match found - do any replacement needed
string sendToUrl = RewriterUtils.ResolveUrl(app.Context.Request.ApplicationPath, re.Replace(requestedPath, rules[i].SendTo));
// log rewriting information to the Trace object
app.Context.Trace.Write("MoleRewriter", "Rewriting URL to " + sendToUrl);
// Rewrite the URL
RewriterUtils.RewriteUrl(app.Context, sendToUrl);
break; // exit the for loop
}
}
// Log information to the Trace object
app.Context.Trace.Write("MoleRewriter", "Exiting MoleRewriter");
}
}
[c-sharp] view plaincopy
protected override void Rewrite(string requestedPath,
System.Web.HttpApplication app)
{
// log information to the Trace object.
app.Context.Trace.Write("MoleRewriter", "Entering MoleRewriter");
// get the configuration rules
RewriterRuleCollection rules =
RewriterConfiguration.GetConfig().Rules;
// iterate through each rule...
for(int i = 0; i < rules.Count; i++)
{
// get the pattern to look for, and Resolve the Url (convert ~ into
the appropriate directory)
string lookFor = "^" +
RewriterUtils.ResolveUrl(app.Context.Request.ApplicationPath,
rules[i].LookFor) + "$";
// Create a regex (note that IgnoreCase is set...)
Regex re = new Regex(lookFor, RegexOptions.IgnoreCase);
// See if a match is found
if (re.IsMatch(requestedPath))
{
// match found - do any replacement needed
string sendToUrl =
RewriterUtils.ResolveUrl(app.Context.Request.ApplicationPath,
re.Replace(requestedPath, rules[i].SendTo));
// log rewriting information to the Trace object
app.Context.Trace.Write("MoleRewriter", "Rewriting URL to " +
sendToUrl);
// Rewrite the URL
RewriterUtils.RewriteUrl(app.Context, sendToUrl);
break; // exit the for loop
}
}
// Log information to the Trace object
app.Context.Trace.Write("MoleRewriter", "Exiting MoleRewriter");
}
}
改为
[c-sharp] view plaincopy
protected override void Rewrite(string requestedPath, System.Web.HttpApplication app)
{
// log information to the Trace object.
app.Context.Trace.Write("MoleRewriter", "Entering MoleRewriter");
// get the configuration rules
RewriterRuleCollection rules = RewriterConfiguration.GetConfig().Rules;
// iterate through each rule...
for(int i = 0; i < rules.Count; i++)
{
// get the pattern to look for, and Resolve the Url (convert ~ into the appropriate directory)
string lookFor = "^" + rules[i].LookFor + "$";
// Create a regex (note that IgnoreCase is set...)
Regex re = new Regex(lookFor, RegexOptions.IgnoreCase);
// See if a match is found
if (re.IsMatch(requestedPath))
{
// match found - do any replacement needed
string sendToUrl = RewriterUtils.ResolveUrl(app.Context.Request.ApplicationPath, re.Replace(requestedPath, rules[i].SendTo));
// log rewriting information to the Trace object
app.Context.Trace.Write("MoleRewriter", "Rewriting URL to " + sendToUrl);
// Rewrite the URL
RewriterUtils.RewriteUrl(app.Context, sendToUrl);
break; // exit the for loop
}
}
// Log information to the Trace object
app.Context.Trace.Write("MoleRewriter", "Exiting MoleRewriter");
}
}
[c-sharp] view plaincopy
protected override void Rewrite(string requestedPath,
System.Web.HttpApplication app)
{
// log information to the Trace object.
app.Context.Trace.Write("MoleRewriter", "Entering MoleRewriter");
// get the configuration rules
RewriterRuleCollection rules =
RewriterConfiguration.GetConfig().Rules;
// iterate through each rule...
for(int i = 0; i < rules.Count; i++)
{
// get the pattern to look for, and Resolve the Url (convert ~ into
the appropriate directory)
string lookFor = "^" + rules[i].LookFor + "$";
// Create a regex (note that IgnoreCase is set...)
Regex re = new Regex(lookFor, RegexOptions.IgnoreCase);
// See if a match is found
if (re.IsMatch(requestedPath))
{
// match found - do any replacement needed
string sendToUrl =
RewriterUtils.ResolveUrl(app.Context.Request.ApplicationPath,
re.Replace(requestedPath, rules[i].SendTo));
// log rewriting information to the Trace object
app.Context.Trace.Write("MoleRewriter", "Rewriting URL to " +
sendToUrl);
// Rewrite the URL
RewriterUtils.RewriteUrl(app.Context, sendToUrl);
break; // exit the for loop
}
}
// Log information to the Trace object
app.Context.Trace.Write("MoleRewriter", "Exiting MoleRewriter");
}
}
就是将
string lookFor = "^" + RewriterUtils.ResolveUrl(app.Context.Request.ApplicationPath, rules[i].LookFor) + "$";
改成了
string lookFor = "^" + rules[i].LookFor + "$";
完成这过程之后将整个项目重新编译一下。
这些都做完之后,
在webconfig配置里面的
<configSections>里面 添加:
[xhtml] view plaincopy
<section name="RewriterConfig" type="URLRewriter.Config., URLRewriter"/>
[xhtml] view plaincopy
<section name="RewriterConfig" type="URLRewriter.Config., URLRewriter"/>
在</configSections>下面添加
[xhtml] view plaincopy
<RewriterConfig>
<!-- 处理默认首页失败-->
<Rules>
<RewriterRule>
<LookFor>http://www/.worldbao/.com/</LookFor>
<SendTo>~/default.aspx</SendTo>
</RewriterRule>
</Rules>
<!-- 处理默认首页失败-->
<!--二级域名正则-->
<Rules>
<RewriterRule>
<LookFor>http://([a-zA-Z|0-9]+)/.worldbao/.com/</LookFor>
<SendTo>/user/user.aspx?us=$1</SendTo>
</RewriterRule>
</Rules>
<!--二级域名正则-->
</RewriterConfig>
[xhtml] view plaincopy
<RewriterConfig>
<!-- 处理默认首页失败-->
<Rules>
<RewriterRule>
<LookFor>http://www/.worldbao/.com/</LookFor>
<SendTo>~/default.aspx</SendTo>
</RewriterRule>
</Rules>
<!-- 处理默认首页失败-->
<!--二级域名正则-->
<Rules>
<RewriterRule>
<LookFor>http://([a-zA-Z|0-9]+)/.worldbao/.com/</LookFor>
<SendTo>/user/user.aspx?us=$1</SendTo>
</RewriterRule>
</Rules>
<!--二级域名正则-->
</RewriterConfig>
在httpMoles里面添加
[xhtml] view plaincopy
<httpMoles>
<add type="URLRewriter.MoleRewriter, URLRewriter" name="MoleRewriter"/>
</httpMoles>
[xhtml] view plaincopy
<httpMoles>
<add type="URLRewriter.MoleRewriter, URLRewriter" name="MoleRewriter"/>
</httpMoles>
2、如何绑定、解析二级域名
就如你发图这样就可以了。
有关A记录、MX记录等DNS的内容,可以网上搜一下。
DNS的生效时间会比较长。一般我们可以用nslookup命令,指定DNS服务器为域名提供商的,再看它能否正常解析。如果可以正常解析,一般就可以了。在互联网上的DNS解析是全球同步的,同步时间很慢,要等几小时才可以在国内同步完。
3、Windows服务器怎么绑定m开头的二级域名
第一步、域名解析:将m开头的二级域名解析到服务器的IP地址上
第二步、域名绑定:如果是windows的服务器一般都是IIS的管理器,进行域名绑定。
步骤如下:
1、在服务器里选择开始菜单里的“interest信息服务(IIS)管理器”进入,然后在“网站”文件展开目录下找到已经建立好的站点,右键选择属性打开该站点属性面板
2、进入站点属性面板后可见“目录安全性”、“HTTP头”、“自定义错误”等选项标签,选择“网站”标签,保持“网站标识”以及“连接”内容的默认值,直接选择“高级”进入“高级网站标识”面板
3、进入“高级网站标识”属性面板后,保持“ip地址”、“TCP端口”、“主机头值”下原有的默认值不变,点击选择“添加”按钮,出现“添加\编辑网站标识”的对话框,保持“IP地址”默认值不变,将“TCP端口”设置成“80”,“主机头值”就是要绑定的域名,可输入要绑定的网址。如:m.baidu.com
4、设置确认保存后可见有新的网站标识显示,这时候已经完成了在该网站绑定域名的操作,点击“确认”按钮即可保存退出
4、怎么绑定二级域名
二级域名绑定的意思就是建立一个分站。二级域名和顶级域名共享一个空间,只不过二级域名的网页放在主站的一个文件夹下。绑定二级域名教程如下:
1、第一步:在万网创建一个新的二级域名
新建二级域名很简单,这个是免费的,不过万网只允许建10个子域名。
首先登录万网账户,进入会员中心。左侧找到“域名管理”-“阿里云解析”
2、在“域名列表”中选择域名,进入管理界面。
3、点“新增解析”就可以直接创建二级域名了。在这里创建和解析是同时完成的。创建后就直接把新域名解析到你的顶级域名所在的空间了。
这里的顶级域名是www.uyouzi.com ,假如开一个论坛,名字是“luntan”,那二级域名就是:luntan.uyouzi.com 配置如下:
记录类型:A记录; 主机记录:luntan ;解析线路:默认;记录值:填你的顶级域名所在空间的ip,ping一下你的顶级域名就知道了;ttl:默认的10分钟就行了。
然后保存即可,几分钟后就会生效。
检测二级域名是否成功解析的操作如下:
打开cmd 输入:ping luntan.uyouzi.com
如果ping通,就解析成功了。
5、如何开通二级域名
可以在服务商的域名解析里面开通二级域名。
1、进入自己的域名服务商,这里以阿里云为例,点击域名后面的“解析设置”按钮进入解析界面:
2、点击“添加记录”按钮添加新的解析:
3、在主机记录这一项输入二级域名的名称,然后在记录值这一项填写自己服务器的地址:
4、点击确定按钮之后二级域名就开通好了,由于域名解析同步需要一段时间,所以开通之后过一会才能使用:
6、如何用二级域名绑定子目录
方案1.
Ftp根目录建立一个新的目录test(第二个站)
将xx.xx.com绑定至主站
写一个脚本,
规则: 一旦访问xx.xx.com 自动跳转 访问根目录下的test目录。
方案2.
同样创建test文件夹
以xx.com/test的方式访问
7、请教二级域名如何绑定到IP
1、内网IP地址的应用的搭建部署。在内网环境,一样可以搭建自己的应用,如网站应用部署,弄好后,在内网可以通过内网IP进行访问连接。
2、内网远程桌面的开通允许。如果需要外网访问内网电脑,首先需要允许远程桌面。
3、花生壳绑定内网IP到域名,并通过访问域名,从而实现访问内网IP应用。对域名进行添加映射使用,设置映射的内网地址。外网端口可以默认分配端口,或使用http80端口访问方式。
4、nat123端口映射绑定内网IP的使用。绑定内网地址时,同时自定义设置外网域名地址,可以使用自己的域名,或默认的二级域名。在绑定内网地址过程中,选择适合自己应用的线路。包括了80映射、https映射、非网站应用、udp映射线路等。
8、请教如何二级域名绑定子目录
二级域名应该单独开一个站点 指向到你想访问的目录, 你现在的设置是和主站点同时绑定访问,当然显示的是网站根目录啦
9、一个虚拟主机如何设置多个二级域名?
虚拟主机想绑定二级域名解决方案如下:
1、在网站根目录新建个.htaccess文件,在此文件中加入以下语句:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?要绑定的域名$
RewriteCond %{REQUEST_URI} !^/目录名/
# 不要改以下两行.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /目录名/$1
# 目录名/ 后面是首页文件index.php, index.html……
RewriteCond %{HTTP_HOST} ^(www.)?要绑定的域名$
RewriteRule ^(/)?$ 目录名/index.php [L]
2、上面的整套语句是绑定一个子目录,绑定多个子目录,可以重复添加以上的全套语句。