Forum Discussion
Need to replace URL and URI
I am looking for a irule so that when I hit john.a.com\A it need to redirect to http://whoisjohn.a.com/shortname=A john.a.com\B it need to redirect to http://whoisjohn.a.com/shortname=B john.a.com\C it need to redirect to http://whoisjohn.a.com/shortname=C
I played around and come up with this and meet my requirements
when HTTP_REQUEST { if {[HTTP::host] contains "john" }
{ HTTP::redirect "http://whoisjohn.a.com/shortname=[substr [HTTP::uri] 1]"
}
}
substr "1" command basically strips of the "/" on the client request
- Dan_73594Historic F5 Account
Hi there - Check out this article from iRules 101. There are some examples you could use with the HTTP::redirect command that would fit your requirements.
Dan
- HectormNimbostratus
when HTTP_REQUEST { set Vuri [ string tolower [HTTP::uri]] set Vheader [string tolower [HTTP::host]]
if { $Vheader equals "john.a.com" } { switch $Vuri { /a { HTTP::redirect "http://whoisjohn.a.com/shortname=A" } /b { HTTP::redirect "http://whoisjohn.a.com/shortname=B" } /c { HTTP::redirect "http://whoisjohn.a.com/shortname=C" } } }
}
- HectormNimbostratus
when HTTP_REQUEST { set Vuri [ string tolower [HTTP::uri]] set Vheader [string tolower [HTTP::host]]
if { $Vheader equals "john.a.com" } { switch $Vuri { /a { HTTP::redirect "http://whoisjohn.a.com/shortname=A" } /b { HTTP::redirect "http://whoisjohn.a.com/shortname=B" } /c { HTTP::redirect "http://whoisjohn.a.com/shortname=C" } } }
}
- johnmervin_4578Altostratus
The problem is "A" "B" "C" are not static it will be dynamic and more than 1000
- Vijay_ECirrus
Untested:
when HTTP_REQUEST { if { ([HTTP::host] eq "john.a.com") and ([string length [HTTP::uri]] < 3) } { set NEW_URI [string map {/ /shortname=} [HTTP::uri]] HTTP::respond 301 Location "http://whois.[HTTP::host]$NEW_URI" } }
- johnmervin_4578Altostratus
I played around and come up with this and meet my requirements
when HTTP_REQUEST { if {[HTTP::host] contains "john" }
{ HTTP::redirect "http://whoisjohn.a.com/shortname=[substr [HTTP::uri] 1]"
}
}
substr "1" command basically strips of the "/" on the client request
Recent Discussions
Related Content
* 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