404错误伪静态类封装class RewriteBase(2)
作者:hayden 来源:烦恼blog 时间:2009-06-29 16:19:00
有兴趣的朋友可以下载RewriteBase类源码玩玩:
压缩包类包括:404.asp、cls_RewriteBase.asp
下载地址:404Rewrite.rar (2.89 KB)
404.asp源码:
<%@ LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
Option Explicit
Session.CodePage = 65001
%>
<!--#include file="cls_RewriteBase.asp"-->
<%
Dim Rewrite
Set Rewrite = new RewriteBase
'Rewrite.Char "utf-8" '设置编码默认为utf-8
'Rewrite.ourl '这里可以测试最初所接收的地址,如我的空间是这样的:http://202.91.239.125/404.asp?404;http://pjskin.mysuc.com:80/style_1149=
Rewrite.ReSetUrl "http[^;]*;([^=]*)=","$1" '通过正则转换
'Rewrite.ourl '这里可以测试是否成功转换为所点击的地址。如:http://pjskin.mysuc.com/style_1149.shtml
'**************************
'伪静态正则规则开始。
'**************************
Rewrite.Rule "(http:[^:]*):80\/style_([0-9]+)\.shtml","$1/?styleid=$2"
'Rewrite.ourl '这里可以测试是否已转换到最后地址,将上一步格式的地址转化成如下:http://pjskin.mysuc.com/styleid=1149
'Rewrite.Rule "^\/article\/([0-9]+)\.htm","/article.asp?id=$1"
'Rewrite.Rule "^\/class_([0-9]+)\.html$","/default.asp?cateID=$1"
'Rewrite.Rule "^\/tag\.htm$","/tag.asp"
'Rewrite.Rule "^\/GuestBook\.html$","/LoadMod.asp?plugins=GuestBookForPJBlog"
'Rewrite.Rule "^\/AboutMe\.html$","/LoadMod.asp?plugins=AboutMeForPJBlog"
'Rewrite.Rule "^\/tag_([^\.])*\.html$","/default.asp?tag=$1"
'**************************
'转换页面中存在的动态地址
'**************************
Rewrite.Src "(href=""[^\?]*)\?styleid=([0-9]+)","$1style_$2.shtml" '将页面里的地址转成伪静态格式的地址。
Set Rewrite = Nothing
%>
<!-- 这儿是404页面内容 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Language" content="UTF-8" />
<title>404错误</title>
<meta name="robots" content="all" />
<meta name="generator" content="editplus" />
<meta name="author" content="hayden@yeah.net,hayden" />
<meta name="Copyright" content="mysuc.com" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<link rel="stylesheet" rev="stylesheet" href="" type="text/css" media="all" />
<style type="text/css">
</style>
<script type="text/javascript" src=""></script>
</head>
<body>
404错误,您所查看的页面已失效。
</body>
下面是cls_RewriteBase的源码:
<%
Class RewriteBase
'===========利用404错误伪静态类==========
' Author:hayden
' Copryright www.mysuc.com
' Update: 2009-06-12
'===========================================
Dim WebUrl,regEx,IsTransfer,Char,pagehtml
Dim srt_sPattern,str_sContent
Private Sub class_initialize()
Set regEx = New RegExp ' 建立正则表达式。
regEx.IgnoreCase = True ' 设置是否区分大小写。
regEx.Global = True ' 设置全局可用性。
IsTransfer = False
Char = "utf-8"
GetUrl
srt_sPattern = ""
str_sContent = ""
end sub
'编码设置
Public Function Setchar(ByVal sChar)
If Len(sChar)>0 Then Char = sChar
End Function
'debug 输出真实地址
Public Function ourl()
Response.Status="200 OK"
response.write WebUrl
response.End
End Function
'正则处理伪静态
Public Function rule(ByVal sPattern,ByVal sContent)
If IsTransfer Then Exit Function
IsTransfer = ReSetUrl(sPattern,sContent)
End Function
'正则式处理
Public Function ReSetUrl(ByVal sPattern,ByVal sContent)
ReSetUrl = False
regEx.Pattern = sPattern ' 设置模式。
If regEx.Test(WebUrl) Then
WebUrl = regEx.Replace(WebUrl, sContent)
ReSetUrl = True
End If
End Function
'整理正则式页面链接规则
Public Function Src(ByVal sPattern,ByVal sContent)
srt_sPattern = srt_sPattern & "|**|" & sPattern
str_sContent = str_sContent & "|**|" & sContent
End Function
'正则式页面链接
Private Function reSrc(ByVal sPattern,ByVal sContent)
regEx.Pattern = sPattern ' 设置模式。
pagehtml = regEx.Replace(pagehtml, sContent)
End Function
'获取取目标URL地址的HTML代码
Private Function steal(ByVal src_)
steal = ""
If Not IsTransfer Then Exit Function
dim Http
set Http=server.createobject("MSXML2.XMLHTTP")
Http.open "GET",src_ ,false
Http.send()
if Http.readystate<>4 then
exit Function
end if
steal=BytesToBSTR(Http.responseBody)
set http=nothing
if err.number<>0 then err.Clear
end Function
'处理页面内容
Private Function checkpage()
If Not IsTransfer Then Exit Function
pagehtml = steal(WebUrl)
Dim i
Dim arr_sPattern,arr_sContent
If Len(srt_sPattern)>0 And Len(str_sContent)>0 Then
arr_sPattern = Split(srt_sPattern,"|**|")
arr_sContent = Split(str_sContent,"|**|")
For i = 1 To UBound(arr_sPattern)
If Len(arr_sPattern(i))>0 Then reSrc arr_sPattern(i),arr_sContent(i)
Next
End If
End Function
'中文处理
Private Function BytesToBstr(ByVal sbody)
dim objstream
set objstream = Server.CreateObject("adodb.stream")
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write sbody
objstream.Position = 0
objstream.Type = 2
objstream.Charset = Char
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function
'获取当前网址
Private Sub GetUrl()
Dim strHostName,strScriptName,strSubUrl,strRequestItem
strHostName = CStr(Request.ServerVariables("LOCAL_ADDR"))
strScriptName = CStr(Request.ServerVariables("SCRIPT_NAME"))
strSubUrl=""
If Request.QueryString <> "" Then
strScriptName = strScriptName & "?"
For Each strRequestItem In Request.QueryString
If InStr(strScriptName,strRequestItem) = 0 Then
If strSubUrl = "" Then
strSubUrl = strSubUrl & strRequestItem & "=" & Server.URLEncode(Request.QueryString("" & strRequestItem & ""))
Else
strSubUrl = strSubUrl &"&" & strRequestItem & "=" & Server.URLEncode(Request.QueryString("" & strRequestItem & ""))
End If
End If
Next
End If
WebUrl = "http://" & strHostName & strScriptName & strSubUrl
End Sub
'建立跳转并关闭对象
Private Sub class_terminate()
checkpage
Set regEx = Nothing
If IsTransfer Then
response.write pagehtml
response.End
End If
end sub
End Class
%>
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
JavaScript中尽量用局部变量的原因[译]
![](https://img.aspxhome.com/file/UploadPic/20092/20/01-88s.jpg)
Silverlight与Flash的技术比较
解析:MySQL对“服务器端光标”的限制
自己重新写了一个JavaScript的对象克隆函数
UTF-8转为GB2312编码的asp函数
Oracle回滚段的概念,用法和规划及问题的解决
IE中雅黑字体给布局带来的变化
![](https://img.aspxhome.com/file/UploadPic/20086/13/2008613122420492s.gif)
SQL Server数据库动态交叉表的参考示例
ASP Framework_1_简介
慢慢的网页
![](https://img.aspxhome.com/file/UploadPic/200911/12/manmanwangye-95s.jpg)
Asp Object 之:AddHeader
在ASP中改善动态分页的性能
Oracle常见错误诊断
使用ewebeditor可能会重复提交数据两次的解决办法
asp如何在本地机器上创建缓存?
IE7的web标准之道 Ⅲ
![](https://img.aspxhome.com/file/UploadPic/20088/20/200882013959967s.jpg)
asp中日期时间函数介绍
WEB3.0时代的开放与聚合
在MySQL数据库中如何修改密码及访问限制
CSS背景图片的运用优化HTTP连接数
![](https://img.aspxhome.com/file/UploadPic/20089/4/200894214417934s.gif)