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 works fine for /Portal/Category/
when HTTP_REQUEST {
if { [HTTP::uri] starts_with "/Portal/Category/" } {
HTTP::uri "/g2p/KII.G2P.Portal.Web.Pages/Category.aspx?id=[substr [HTTP::uri] 17 "\/"] "
}
}
But my issue is that I have a hundreds of entries in my ISAPI file and not all of them are /portal/category/ some do have the /portal/"somthing differnet", some have a different somthing/something. Obviously I don’t want to create hundreds of iRules or an iRule that has hundreds of “if then else” statements. Does anyone have any other suggestion or thoughts.
Below is a small example of some of the rewrites in my ISAPI file:
RewriteCond Host: test.mysite.com
RewriteRule /Portal/Search\.aspx(.*) /g2p/file.G2P.Portal.Web.Pages.Google/Search.aspx$1 [I]
RewriteCond Host: test.mysite.com
RewriteRule /Portal/SearchProxy\.aspx(.*) /g2p/file.G2P.Portal.Web.Pages.Google/SearchProxy.aspx$1 [I]
RewriteCond Host: test.mysite.com
RewriteRule /Portal/etc/(.*) /g2p/file.G2P.Portal.Web.Pages.Google/etc/$1 [I]
RewriteCond Host: test.mysite.com
RewriteRule /Portal/ExternalLink\.aspx(.*) /g2p/KII.G2P.Portal.Web.Pages/ExternalLink.aspx$1 [I]
RewriteCond Host: www\.test\.mayor\.state\.com
RewriteHeader Host: .* mayor\.state\.com
RewriteCond Host: test\.mayor\.state\.com
RewriteHeader Host: .* mayor\.state\.com
RewriteCond Host: cms\.test\.state\.mayor\.com
RewriteHeader Host: .* mayor\.state\.com
RewriteCond Host: test\.agency\.state\.com
RewriteHeader Host: .* agency\.state\.com
RewriteCond Host: www\.test\.agency\.state\.com
RewriteHeader Host: .* agency\.state\.com
RewriteCond Host: test\.cms\.agency\.state\.com
RewriteHeader Host: .* agency\.state\.com
RewriteCond Host: test\.another_agency\.state\.com
RewriteHeader Host: .* commerce\.state\.com
RewriteCond Host: www\.test\.another_agency \.state\.com
RewriteHeader Host: .* another_agency\.state\.com
RewriteCond Host: cms\.test\.another_agency \.state\.com
RewriteHeader Host: .* another_agency\.state\.com
Thanks in advance…
Bob
- hooleylistCirrostratusHi Bob,
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])" }
- Bob_10976NimbostratusAaron....Thanks for the reply and example.
- hooleylistCirrostratusI think a switch statement is most efficient up to a point (50 - 100 entries?). Beyond that, your idea for classes would probably be more efficient. I don't think either option would add significant latency though.
- Bob_10976NimbostratusWould it be possible for an example of the classes functions, in regards to the ISAPI portion I posted?
- Xin_99652NimbostratusI need change http://mycompany.com/section_one/..... to http://www.mycompany.com/section_one/... can I do it by using iRule? thanks,
- hooleylistCirrostratusHi there,
when HTTP_REQUEST { Check host header if {[string tolower [HTTP::host]] eq "mycompany.com"}{ Redirect client to www.mycompany.com with the same URI HTTP::redirect "http://www.mycompany.com[HTTP::uri]" } }
- Bob_10976NimbostratusMy actual rule I'm using...
- Xin_99652NimbostratusHi Aaron/BobMc,
- Xin_99652NimbostratusHi there,
- If you set the default pool on your virtual server to "pl_www_mycompany_com" then you will not have to specify it in the iRule. That is the preferred method unless there is some reason why you have another default pool setup.
when HTTP_REQUEST { switch [string tolower [HTTP::host]] { "www.mycompany.com" { } "mycompany.com" { HTTP::redirect "http://www.mycompany.com[HTTP::uri]" } default { reject } } }
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