Forum Discussion
Bob_10976
May 12, 2008Nimbostratus
iRule re-write to replace ISAPI re-write
Hello all...
We are currently using ISAPI re-write in our portal to re-write uri's to the appropriate location. With the help of this forum I came up with the following, which work...
hooleylist
May 13, 2008Cirrostratus
Hi Bob,
It looks like you're trying to modify what we call the path within the URI, without modifying the query string. In the isapi configuration, you're using regexes with backreferences. In iRules you can do this more efficiently with string commands and/or the default HTTP:: commands (Click here).
For a URL of:
http://www.example.com/path/to/file.ext?param1=value1¶m2=value2
The Host, www.example.com, can be retrieved using HTTP::host (Click here).
You can set the Host header value using 'HTTP::header replace Host newhost.example.com' (Click here)
The path, /path/to/file.ext, can be retrieved or set using the HTTP::path command (Click here)
Most of your rewrite conditions are based on the host header. You can use switch commands to efficiently handle the cases.
when HTTP_REQUEST {
Log a debug message to /var/log/ltm with the original host and URI. Comment out/remove once done testing.
log local0. "[IP::client_addr]:[TCP::client_port]: new request to [HTTP::host][HTTP::uri] (path: [HTTP::path])"
switch [string tolower [HTTP::host]] {
"test.mysite.com" {
Request was to host test.mysite.com, so check the path and do path rewrites
log local0. "[IP::client_addr]:[TCP::client_port]: matched test.mysite.com, checking path"
switch [HTTP::path] {
"/Portal/Search.aspx" {
Update path
log local0. "[IP::client_addr]:[TCP::client_port]: matched test.mysite.com/Portal/Search.aspx, \
updating path to /g2p/file.G2P.Portal.Web.Pages.Google/Search.aspx"
HTTP::path "/g2p/file.G2P.Portal.Web.Pages.Google/Search.aspx"
}
"/Portal/SearchProxy.aspx" {
Update path
log local0. "[IP::client_addr]:[TCP::client_port]: matched test.mysite.com/Portal/SearchProxy.aspx, \
updating path to /g2p/file.G2P.Portal.Web.Pages.Google/SearchProxy.aspx"
HTTP::path "/g2p/file.G2P.Portal.Web.Pages.Google/SearchProxy.aspx"
}
"/Portal/etc/" {
Update path
log local0. "[IP::client_addr]:[TCP::client_port]: matched test.mysite.com/Portal/etc/, \
updating path to /g2p/file.G2P.Portal.Web.Pages.Google/etc/"
HTTP::path "/g2p/file.G2P.Portal.Web.Pages.Google/etc/"
}
"/Portal/ExternalLink.aspx" {
Update path
log local0. "[IP::client_addr]:[TCP::client_port]: matched test.mysite.com/Portal/ExternalLink.aspx, \
updating path to /g2p/KII.G2P.Portal.Web.Pages/ExternalLink.aspx"
HTTP::path "/g2p/KII.G2P.Portal.Web.Pages/ExternalLink.aspx"
}
}
}
"www.test.mayor.state.com" {
Rewrite Host header
HTTP::header replace Host "mayor.state.com"
}
}
}
when HTTP_REQUEST priority 501 {
This event and code is here just to allow logging of the updated Host and path values
These commands returned cached values when executed multiple times in the same event.
Log a debug message to /var/log/ltm with the modified host and URI. Remove once done testing.
log local0. "[IP::client_addr]:[TCP::client_port]: updated host/uri [HTTP::host][HTTP::uri] (path: [HTTP::path])"
}
Aaron
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