Joe_Pipitone
Mar 02, 2011Nimbostratus
Regex
I've been requested to perform a rewrite / redirect which does the following:
http://subdomain.ourcompany.com/webext/01.aspx?status=error (pass the 01 over to the url below and say id=thatNu...
Let's step back a bit and rethink the problem. Whenever I hear "regex" I cringe because it's such a costly operation. In some cases, it's the only way to go, but for this case where you know the format of the inbound URI, it's fairly easy to use the TCL string functions to extract the value of ID. Something like this should work for you
when HTTP_REQUEST {
Lowercase the URI for string comparison purposes (.aspx implies case-insensitive URIs)
set uri [string tolower [HTTP::uri]]
Only process URIs of the format /webext/xxxxx.aspx?status=error
if { ($uri starts_with "/webext/") && ($uri ends_with ".aspx?status=error") } {
Set the start index to the first char after "/webext/" in the URI
set idxStart 8
Set the end index to the dot in ".aspx".
set idxEnd [string first ".aspx" $uri]
if { -1 != $idxEnd } {
decrement the end index to the last character in the id
incr idxEnd -1;
extract the id from the uri from the uri
set id [string range $uri $idxStart $idxEnd]
Issue the redirect
HTTP::redirect "http://[HTTP::host]/post/post.ashx?id=${id}&status=error"
}
}
}
Granted, I made some assumptions here that you won't be handling URI's with both numbers/characters between the "/webext/" and ".aspx?status=error". It should still work, but it will replace the value of the "id" variable with whatever is between those two strings.
Hope this helps...
-Joe