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
%>

 

标签:错误,404,伪静态,封装
0
投稿

猜你喜欢

  • JavaScript中尽量用局部变量的原因[译]

    2009-02-20 13:45:00
  • Silverlight与Flash的技术比较

    2009-04-19 18:45:00
  • 解析:MySQL对“服务器端光标”的限制

    2008-11-27 16:22:00
  • 自己重新写了一个JavaScript的对象克隆函数

    2008-08-03 16:47:00
  • UTF-8转为GB2312编码的asp函数

    2007-08-23 13:42:00
  • Oracle回滚段的概念,用法和规划及问题的解决

    2010-07-26 13:08:00
  • IE中雅黑字体给布局带来的变化

    2008-06-13 11:22:00
  • SQL Server数据库动态交叉表的参考示例

    2009-01-04 14:44:00
  • ASP Framework_1_简介

    2009-10-12 11:35:00
  • 慢慢的网页

    2009-11-12 12:53:00
  • Asp Object 之:AddHeader

    2008-05-05 12:58:00
  • 在ASP中改善动态分页的性能

    2008-05-08 14:27:00
  • Oracle常见错误诊断

    2010-07-27 12:56:00
  • 使用ewebeditor可能会重复提交数据两次的解决办法

    2009-01-09 12:41:00
  • asp如何在本地机器上创建缓存?

    2010-06-18 19:27:00
  • IE7的web标准之道 Ⅲ

    2008-08-20 12:55:00
  • asp中日期时间函数介绍

    2013-06-01 20:01:03
  • WEB3.0时代的开放与聚合

    2008-08-21 17:19:00
  • 在MySQL数据库中如何修改密码及访问限制

    2008-11-27 16:36:00
  • CSS背景图片的运用优化HTTP连接数

    2008-09-04 21:38:00
  • asp之家 网络编程 m.aspxhome.com