导航:首页 > IDC知识 > iis7二级域名子目录

iis7二级域名子目录

发布时间:2021-02-06 14:47:38

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、请教如何二级域名绑定子目录

二级域名应该单独开一个站点 指向到你想访问的目录, 你现在的设置是和主站点同时绑定访问,当然显示的是网站根目录啦

3、网站二级目录怎么绑定二级域名?IIS主机

首先需要你的域名服务器允许添加二级域名目录,操作起来和一级域名的一样,如果允许操作,再设定个首页访问就可以了

4、iis下如何绑定二级目录

又不是二级域名的绑定
你要新绑定一个二级目录
直接在IIS新建一个站点
然后指定根目录为blog不就好了

5、iis里怎么设置二级域名指向子目录?

推荐你使用 N点虚拟主机管理系统 完全免费。里面就可设置二级域名绑定子目录功能。或者在IIS里面再新建一个网站绑定你的二级域名,然后把文件目录指向你要设置的子目录。

6、如何绑定子域名(二级域名)到子目录?

具体操作步骤如下:1、进入思跃主机控制面板,点击“子域名管理”;2、输入您要绑定的版子域权名,例如:输入blog.domain.com即可绑定blog目录。3、您绑定的子域名会自动对应网站根目录下的同名目录。(例如:您绑定了blog.domain.com,如果您的根目录下已有blog目录,那么系统在绑定blog目录后,还将会自动生成一个index.html,放在您的blog目录下,您在绑定后直接删除此文件即可;如果您的根目录下没有对应目录,那么系统会自动生成一个blog目录来对应您绑定的子域名)注意:思跃主机控制面板不支持顶级域名绑定子目录。

7、IIS二级域名绑定子目录

首先,你的域名必须支持泛绑定其次可以在主目录下建个bbs存放论坛然后在IIS管理面板中,右击新建虚拟目录,目录指向你刚才建立的bbs最后在主机头设置时,设为空

8、IIS二级域名绑定子目录的问题

二级域名应该单独开一个站点 指向到你想访问的目录, 你现在的设置是和主站点同时绑定访问,当然显示的是网站根目录啦

与iis7二级域名子目录相关的知识