现在有很多“多个域名绑定一个空间”的代码。
但都是跳转的,
1.对搜索引擎不友好。
2.而且网址跳转后也不美观了。

今天无事,就弄了个不跳转的ASP代码,有利于搜索引擎的收录,也不跳转。

<%
domain=lcase(request.servervariables(“HTTP_HOST”))

if instr(domain,”zhongguoren.cn”)>0 then
filename=”zhongguoren.htm”

elseif instr(domain,”kandianshi.com”)>0 then
filename=”kandianshi.htm”

end if
%>

<%
Function include(filename)
Dim re,content,fso,f,aspStart,aspEnd

set fso=CreateObject(“Scripting.FileSystemObject”)
set f=fso.OpenTextFile(server.mappath(filename))
content=f.ReadAll
f.close
set f=nothing
set fso=nothing

set re=new RegExp
re.pattern=”^s*=”
aspEnd=1
aspStart=inStr(aspEnd,content,”<%”)+2
do while aspStart>aspEnd+1
Response.write Mid(content,aspEnd,aspStart-aspEnd-2)
aspEnd=inStr(aspStart,content,”%>”)+2
Execute(re.replace(Mid(content,aspStart,aspEnd-aspStart-2),”Response.Write “))
aspStart=inStr(aspEnd,content,”<%”)+2
loop
Response.write Mid(content,aspEnd)
set re=nothing
End Function

include(“”&filename&””)
%>

将上面的代码放在根目录,命名为:index.asp

然后将各个站点的首页改名为:zhongguoren.htm;kandianshi.htm;等。。

当访问者访问 http://zhongguoren.cn 时,自动加载:zhongguoren.htm 的内容。
当访问者访问 http://kandianshi.com 时,自动加载:kandianshi.htm 的内容。

注意:是直接在index.asp显示相应的内容,而不是跳转到相应的页面。

From:http://hi.baidu.com/sunlovestar/blog/item/fb7362095313d5cd3bc7631a.html

赞赏

微信赞赏支付宝赞赏

「赏不在多,觉得文章有用,就赞赏下吧!」

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据