1、二級域名綁定子目錄-子目錄綁定數量-網站子目錄綁...
二級域名綁定子目錄-子目錄綁定數量-網站子目錄綁...
個需要設置一個功能,也就是robots.txt(搜索引擎協議)第一個網站上面的robots.txt裡面寫上屏蔽搜索引擎抓取你的子目錄名,
robots.txt格式為
User-agent:*
Disallow: /zml/
User-agent:*是代表所有搜索引擎(即所有搜索引擎都不允許抓取一下內容)
Disallow: /zml/ zml就是你的那個子目錄名字,意思就是不允許搜索引擎抓取查看這個目錄下的所有內容
參考資料:
2、二級域名綁定子目錄每個都要新建站點嗎?
是一個站點,站點下的文件夾用二級域名來梆定,所以不需要重新建站點。
3、如何設置二級域名+綁定網站的子目錄
什麼平台?不同的伺服器平台有不同的設置方法!
4、請教如何二級域名綁定子目錄
二級域名應該單獨開一個站點 指向到你想訪問的目錄, 你現在的設置是和主站點同時綁定訪問,當然顯示的是網站根目錄啦
5、如何做到訪問二級域名指向我網站根目錄的二級目錄呢?
這個方法倒是不少,不過要根據自己的具體環境參考選擇:
方法一:用js跳轉
在空間上分別綁定www.aaa.com和www.bbb.com
把www.aaa.com網站文件傳到根目錄,把www.bbb.com網站傳到./bbb/目錄
把下面的代碼保存為domain.js,然後上傳到空間根目錄
JavaScript代碼
switch(location.host){
case'www.bbb.com':
location.href="http://www.boaer.com/bbb/"
break;
}
往空間根目錄的首頁的<head>與</head>之間加入<scriptlanguage='javascript'src="/bbb/domain.js"></script>當輸入www.aaa.com訪問時看不到任何變化,但是當輸入www.bbb.com訪問時,瀏覽器自動跳轉到www.bbb.com/bbb/。
要實現多個網站可以依此類推。或者直接在頭部添加類似如下代碼:
<script language=javascript>
if (document.domain =='www.boaer.com')
this.location = "www.bbb.com" + this.location.pathname + this.location.search;
</script>
方法二:(推薦)
用server.Transfer("")來實現一個空間多個站的方法
先將所有的域名綁定到您的虛擬主機上,然後將虛擬主機根目錄中的index.asp(首頁文件)里加入下列代碼就可以了:ASP/Visual Basic代碼
<%
sn=lcase(Request.ServerVariables("SERVER_NAME")) '用於獲取用戶是通過哪個域名訪問的,並轉換成小寫
if sn="www.abc.net" or sn="abc.net" then server.Transfer("default1.asp")
if sn="www.def.net" or sn="def.net" then server.Transfer("index.html")
%>
效果:如果輸入的域名是www.abc.net或abc.net的話,就訪問default1.asp頁面,如果是用def.net或www.def.net的話就調用index.html文件。
方法三:(最方便管理,一個空間放的站越多越推薦)
方法是利用一個asp文件通過瀏覽器輸入的域名,判定是要打開那個文件夾里的站點,來實現一個虛擬放置多個站點(缺點例如打開abc.com,在瀏覽器中看到的是abc.com/b因為站點在b目錄下)
其他說明:如果虛擬主機不支持子目錄綁定,這是非常有效的辦法實現方法如下 :先建立一個默認主頁index.asp,把A站放在A文件夾下,B站放在B文件夾下,C站放在C文件夾下。 index.asp網頁文件如下 :
ASP/Visual Basic代碼
<%if Request.ServerVariables("SERVER_NAME")="www.a.com " then
response.redirect "a/index.asp"
elseif Request.ServerVariables("SERVER_NAME")="www.b.com " then
response.redirect "b/index.asp"
elseif Request.ServerVariables("SERVER_NAME")="www.c.com " then
response.redirect "c/index.asp"
else
response.redirect "aaa/index.asp"
end if%>
代碼作用說明:
如果用戶訪問 www.a.com 程序跳轉至 空間目錄下 a/index.asp
如果用戶訪問 www.b.com 程序跳轉至 空間目錄下 b/index.asp
如果用戶訪問 www.c.com 程序跳轉至 空間目錄下 c/index.asp
如果用戶訪問 沒有指定的 程序跳轉至 空間目錄下 aaa/index.asp
elseif Request.ServerVariables("SERVER_NAME")="www.b.com " then
response.redirect "b/index.asp"
這段是可以無限復制的,一個虛擬主機放幾百個站點就是自己設置的了只要把域名都綁定在虛擬主機上,然後設置這個域名所綁定的站點就OK了,這種要看虛擬主機能綁多少個玉米。能綁100個的話就能放100個站,並且利於網站管理,這樣做可以根據文件夾名,就知道這個是哪個站。
PHP空間的方法
利用PHP是可以實現這個功能的。不但讓他運行多個網站,而且還可以實現每個網站獨立域名。下面把詳細的步驟說明一下。首先了解一下$_SERVER['HTTP_HOST']變數。這個變數在PHP中是用來取瀏覽器中所輸入的地址的。可以實現上面的功能了
先把需要的兩個域名解析到空間。比如:www.***com 和 www.***.cn 兩個域名。如果有更多的域名也沒關系。方法是一樣的。
把默認文檔設置為index.php,當然空間需要是支持PHP的哦。:)
3、利用if ... else 來判斷來訪地址,並作出分析。代碼如下:
<?if($_SERVER['HTTP_HOST']=="www.123.com";){?>
<META HTTP-EQUIV="Refresh" CONTENT="1;URL=http://www.123.com/main">
<?}else if($_SERVER['HTTP_HOST']=="mycalf.com"){?>
<META HTTP-EQUIV="Refresh" CONTENT="1;URL=http://123.com/main">
<?}else if($_SERVER['HTTP_HOST']=="www.456.cn";){?>
<META HTTP-EQUIV="Refresh" CONTENT="1;URL=http://www.456.cn/home">
<?}else{?>
<META HTTP-EQUIV="Refresh" CONTENT="1;URL=http://www.456cn/home">
<?}?>
4、完成
這里要說明的一點是,有的時候域名是用大寫的,那麼就需要對$_SERVER['HTTP_HOST']這個變數進行處理,來讓他把所有的字元轉換成小寫。
代碼如下:
<?
$querystring = preg_replace(array("/()/","/_/"),array("","-"),$_SERVER["QUERY_STRING]);
$I = strtolower(trim($_SERVER['HTTP_HOST']));
?>
如果是這樣寫,就需要把上面的<?if($_SERVER['HTTP_HOST']=="www.123.com";){?>這句變為<?if($I=="www.123.com";){?>,這樣就可以在輸入網址是大寫的時候,也可以正常訪問了。
這個方法也有一個不足點,就是需要在域名後面跟一個目錄名。但是如果你不怕亂的話,也可以把兩個網站都放到根目錄下。但是推薦是每個網站一個目錄。現在許多空間商,都支持5個以內的域名的解析。這樣就可以買一個空間,擁有5個網站了。
這個辦法的優勢也是有的,他每個域名都是可以訪問其他網站的,比如輸http://www.123.com/home/ 與訪問http://www.123.cn/ 域名得到的效果是一樣的。
其實空間麻煩的是資料庫問題,不過資料庫也是可以多個網站共享一個資料庫的,只要不讓表名一樣就可以了。訪問起來道理差不多。
6、二級域名怎麼綁定網站子目錄
如果主機管理後台支持子目錄綁定的話 就可以用域名綁定到對應的子目錄即可
這個功能好多虛擬主機不給予支持的 具體可咨詢服務商
7、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>
8、IIS二級域名綁定子目錄的問題
二級域名應該單獨開一個站點 指向到你想訪問的目錄, 你現在的設置是和主站點同時綁定訪問,當然顯示的是網站根目錄啦
9、如何用二級域名綁定子目錄
方案1.
Ftp根目錄建立一個新的目錄test(第二個站)
將xx.xx.com綁定至主站
寫一個腳本,
規則: 一旦訪問xx.xx.com 自動跳轉 訪問根目錄下的test目錄。
方案2.
同樣創建test文件夾
以xx.com/test的方式訪問
10、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>