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的静态页面试试看可以正常访问吗内?如果可以,容那就是你的程序的问题。如果还是不可以,你就可以再资讯资讯空间商。
还有,方便的话把你的的乱码贴出来。我们看看。