導航:首頁 > 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二級域名子目錄相關的知識