Im wondering if someone could help me.
I have the following URL ( which is dynamic )
www.website.com/images/gal/boxes-pic004.asp
How can i extract the 'boxes-pic004' part using classic ASP
Thanks
<%
Dim sScriptLocation, sScriptName, iScriptLength, iLastSlash
sScriptLocation = Request.ServerVariables("URL")
iLastSlash = InStrRev(sScriptLocation, "/")
iScriptLength = Len(sScriptLocation)
sScriptName = Right(sScriptLocation, iScriptLength - iLastSlash)
%>
sScriptName
will then contain boxes-pic004.asp
, then you can use Replace(sScriptName, ".asp", "")
to remove the extension as well.
Just you can try to output all ServerVariables like,
Eg Page Url: https://www.google.com/gmail/inbox.asp?uid=1421&skyid=2823595
Dim strProtocol
Dim strDomain
Dim strPath
Dim strQueryString
Dim strFullUrl
If lcase(Request.ServerVariables("HTTPS")) = "on" Then
strProtocol = "https"
Else
strProtocol = "http"
End If
strDomain= Request.ServerVariables("SERVER_NAME")
strPath= Request.ServerVariables("SCRIPT_NAME")
strQueryString= Request.ServerVariables("QUERY_STRING")
strFullUrl = strProtocol & "://" & strDomain & strPath
If Len(strQueryString) > 0 Then
strFullUrl = strFullUrl & "?" & strQueryString
End If
Response.Write "Domain : " & strDomain & "</br>"
Response.Write "Path : " & strPath & "</br>"
Response.Write "QueryString : " & strQueryString & "</br>"
Response.Write "FullUrl : " & strFullUrl & "</br>"
Output:
Domain : www.google.com
Path : /gmail/inbox.asp
QueryString : uid=1421&skyid=2823595
FullUrl : https://www.google.com/gmail/inbox.asp?uid=1421&skyid=2823595
Simple
Just use Request.ServerVariables("SCRIPT_NAME")
and then do some string chopping to get the stuff you need.
I think this would depend on the method you used to do the URL rewriting.
Using IIS - Refer to this previous post on how to extract the full URL: get current url of the page (used URL Rewrite)
Using 404 - This is how I've done it in the past and the only way to access the raw URL is to check the querystring. The 404 URL will look something like this:
https://website.com/rewrite.asp?404;http://website.com/images/gal/boxes-pic004.asp
To get the URL, I use something like this:
Function getURL()
Dim sTemp
sTemp = Request.Querystring
' the next line removes the HTTP status code that IIS sends, in the form "404;" or "403;" or whatever, depending on the captured error
sTemp = Right(sTemp, len(sTemp) - 4)
' the next two lines remove both types of server names that IIS includes in the querystring
sTemp = replace(sTemp, "http://" & Request.ServerVariables("HTTP_HOST") & ":80/", "")
sTemp = replace(sTemp, "http://" & Request.ServerVariables("HTTP_HOST") & "/", "")
sTemp = replace(sTemp, "https://" & Request.ServerVariables("HTTP_HOST") & "/", "")
sTemp = replace(sTemp, "https://" & Request.ServerVariables("HTTP_HOST") & ":443/", "")
' the next bit of code will force our array to have at least 1 element
getURL = sTemp
End Function
This will get you the full raw URL, you can then extract the part you need by using simple split like:
tmpArr = Split(getURL(),"/")
strScriptName = tmpArr(UBound(tmpArr))
The strScriptName variable will then return "boxes-pic004.asp".
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With