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、上面的整套語句是綁定一個子目錄,綁定多個子目錄,可以重復添加以上的全套語句。