1、二級域名綁定子目錄-子目錄綁定數量-網站子目錄綁...
二級域名綁定子目錄-子目錄綁定數量-網站子目錄綁...
個需要設置一個功能,也就是robots.txt(搜索引擎協議)第一個網站上面的robots.txt裡面寫上屏蔽搜索引擎抓取你的子目錄名,
robots.txt格式為
User-agent:*
Disallow: /zml/
User-agent:*是代表所有搜索引擎(即所有搜索引擎都不允許抓取一下內容)
Disallow: /zml/ zml就是你的那個子目錄名字,意思就是不允許搜索引擎抓取查看這個目錄下的所有內容
參考資料:
2、apache如何實現二級域名綁定子目錄
好果是伺服器或VPS,修改apache的配置文件httpd.conf ,每一塊VirtualHost都是一個網站配置,添加內容如下:
<VirtualHost www.test.com:80> # 網站名和埠
ServerAdmin [email protected] # 管理員郵箱
DocumentRoot "/usr/local/apache/htdocs" #對應綁定的目錄
ServerName www.test.com #域名綁定。
ErrorLog logs/www_error_log.txt # 錯誤日誌
CustomLog logs/www_log.txt common
</VirtualHost>
# 下面是二級域名的綁定
<VirtualHost bbs.test.com:80> # 網站名和埠
ServerAdmin [email protected]
DocumentRoot "/usr/local/apache/htdocs/bbs" #對應綁定的目錄
ServerName bbs.test.com # 要綁定的二級域名
ErrorLog logs/bbs_error_log.txt
CustomLog logs/bbs_log.txt common
</VirtualHost>
3、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>
4、請教如何二級域名綁定子目錄
二級域名應該單獨開一個站點 指向到你想訪問的目錄, 你現在的設置是和主站點同時綁定訪問,當然顯示的是網站根目錄啦
5、二級域名怎麼綁定子目錄
如果是iis的話
就是在這個管理界面裡面建立一個虛擬目錄,指向你的網站
然後再這個站點滑鼠右鍵進入到它的屬性設置,網站標簽項裡面有個「高級」按鈕
添加你的二級域名為主機頭值
前提是你的二級域名可以實用
6、怎麼用.htaccess綁定二級域名到子目錄
通過.htaccess文件設置重定向,把二級域名綁定到指定的子目錄。
先把要綁定的域名A記錄或CNAME也指向和主域名所在的主機IP,然後可以.htaccess通過如下代碼綁定相應文件夾:
代碼如下
復制代碼
RewriteEngine on
RewriteCond %{HTTP_HOST} ^bbs.domain.com$
RewriteCond %{REQUEST_URI} !^/bbs/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /bbs/$1
RewriteCond %{HTTP_HOST} ^bbs.domain.com$
RewriteRule ^(/)?$ bbs/index.php [L]
如果很多個二級域名都指定的話,每個都這么寫.htaccess文件就會非常龐大臃腫,可以使用以下正則匹配寫法:
代碼如下
復制代碼
RewriteCond %{HTTP_HOST} ^(bbs|blog|download).domain.com$
RewriteRule ^(.*)$ /%1/$1 [L, NC]
這樣,會自動把bbs對應到bbs目錄,blog對應到blog目錄,download對應到download,要加新的域名時,只需要在上面那行按格式添加即可。
7、如何用二級域名綁定子目錄
方案1.
Ftp根目錄建立一個新的目錄test(第二個站)
將xx.xx.com綁定至主站
寫一個腳本,
規則: 一旦訪問xx.xx.com 自動跳轉 訪問根目錄下的test目錄。
方案2.
同樣創建test文件夾
以xx.com/test的方式訪問
8、二級域名綁定子目錄
把你子目錄下面的源程序先刪除了。然後放歌index.htm的靜態頁面試試看可以正常訪問嗎內?如果可以,容那就是你的程序的問題。如果還是不可以,你就可以再資訊資訊空間商。
還有,方便的話把你的的亂碼貼出來。我們看看。