IIS ColdFusion中的目录特定URL重写

时间:2015-12-16 15:14:01

标签: mod-rewrite iis coldfusion

我有网站 Dim s As String = "Aaot:1980" Dim i As Integer If Integer.TryParse(s.SubString(5, s.Length - 6), i) Then Msgbox("The number in the string is " & i.ToString) Else MsgBox("Number could not be parsed") End If

另外,我有另一个链接Public Function GetPDFData(URL As String, TipoDato As Integer) As String Dim oFS As Object Dim strFilename As String CreateFolder DownloadFile (URL) strFilename = "C:\Temp\pdfTemporal\" & NombreDeArchivo(URL) Set oFS = CreateObject("Scripting.FileSystemObject") Select Case TipoDato Case 1 GetPDFData = NombreDeArchivo(URL) Case 2 GetPDFData = oFS.GetFile(strFilename).DateCreated Case 3 GetPDFData = oFS.GetFile(strFilename).DateLastModified Case 4 GetPDFData = pagecount(strFilename) Case 5 GetPDFData = oFS.GetFile(strFilename).Size / 1024 & "Kb" Case 6 GetPDFData = oFS.GetFile(strFilename).Type Case Else GetPDFData = "ERROR" End Select Set oFS = Nothing DeleteFolder End Function Sub DownloadFile(myURL As String) Dim TextUrl As String TextUrl = myURL Dim WinHttpReq As Object Set WinHttpReq = CreateObject("Microsoft.XMLHTTP") WinHttpReq.Open "GET", myURL, False WinHttpReq.send myURL = WinHttpReq.responseBody If WinHttpReq.Status = 200 Then Set oStream = CreateObject("ADODB.Stream") oStream.Open oStream.Type = 1 oStream.Write WinHttpReq.responseBody oStream.SaveToFile "c:\Temp\pdfTemporal\" & NombreDeArchivo(TextUrl), 2 ' 1 = no overwrite, 2 = overwrite oStream.Close End If End Sub Sub CreateFolder() Dim Path As String, NombreCarpeta As String Path = "c:\Temp\" NombreCarpeta = "pdfTemporal" If Dir(Path, vbDirectory) <> "" Then If Dir(Path & NombreCarpeta, vbDirectory) = "" Then MkDir Path & NombreCarpeta End If End Sub Sub DeleteFolder() On Error Resume Next Kill "c:\Temp\pdfTemporal\*.*" RmDir "c:\Temp\pdfTemporal\" On Error GoTo 0 End Sub Public Function NombreDeArchivo(URL As String) As String Dim a As String Dim esp As String esp = " " a = URL For i = 1 To 500 esp = esp & " " Next i a = Replace(a, "/", esp) a = Right(a, 500) a = Trim(a) NombreDeArchivo = a End Function Public Function pagecount(sfilename As String) As String Dim pages As Long On Error GoTo a Dim nFileNum As Integer Dim s As String Dim c As Integer Dim pos, pos1 As Integer pos = 0 pos1 = 0 c = 0 nFileNum = FreeFile Open sfilename For Binary Lock Read Write As #nFileNum Do Until EOF(nFileNum) Input #1, s c = c + 1 If c <= 10 Then pos = InStr(s, "/N") End If pos1 = InStr(s, "/count") If pos > 0 Or pos1 > 0 Then Close #nFileNum s = Trim(Mid(s, pos, 10)) s = Replace(s, "/N", "") s = Replace(s, "/count", "") s = Replace(s, " ", "") s = Replace(s, "/", "") For i = 65 To 125 s = Replace(s, Chr(i), "") Next pages = Val(Trim(s)) If pages < 0 Then pages = 1 End If Close #nFileNum pagecount = pages Exit Function End If If c >= 10000 Then GoTo a End If Loop Close #nFileNum pagecount = pages Exit Function a: Close #nFileNum pages = 1 pagecount = pages Exit Function End Function

我想写一个URL重写规则,它总是重写http://example.com/school/student.cfm?id=100http://example.com/collage/student.cfm?id=200

http://example.com/school/student.cfm?id=100http://example.com/school/student/100

我写了这样的规则,但总是使用1个目录,但我希望这个适用于所有目录。

http://example.com/collage/student.cfm?id=200

1 个答案:

答案 0 :(得分:0)

有很多方法可以解决这个问题。解决方案的范围从 - 仅重写学校和拼贴 - 到重写任何以学生结束的路径 - 再到使用重写所有内容的通用模式。

通过IIS'regexp:

告诉您如何做到这一点
<match url="^(collage|school)/student/([0-9]+)/?$" />
<action type="Rewrite" url="{R:1}/student.cfm?id={R:2}" />

<match url="^([^/]+)/student/([0-9]+)/?$" />
<action type="Rewrite" url="{R:1}/student.cfm?id={R:2}" />

<match url="^([^/]+)/([^/]+)/([0-9]+)/?$" />
<action type="Rewrite" url="{R:1}/{R:2}.cfm?id={R:3}" />