Forum Discussion
Joe_Pipitone
Nimbostratus
Mar 02, 2011Regex
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...
Mar 02, 2011
The reason the match doesn't work is that the sections between the brackets represents a single character. I'm not sure how the interpreter will deal with 999 in this case, but it's not the way you are thinking.
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
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects