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>