Forum Discussion
DM_5174
May 23, 2011Nimbostratus
merging two irules into one efficient one.
Hi All,
I was wondering if there is a way to merge two irules into one effcient one. The first irule checks the host
and if a user is coming in as www.mysite.com, it will rewrite the host header to www.mynewsite.com, and if nothing matches, it should redirect all inbound http request to httpS.
The second irule uses a datagroup string that matches the URI. so if the users puts in
http://www.mynewsite.com/abc/app1 they will get redirected to http://www.mynewsite.com/123/app100
Thanks!
-DMiRule 1
when HTTP_REQUEST { Check if the Host is www.mysite.com
if { [string tolower [HTTP::host]] eq "www.mysite.com"} {
Rewrite the Host header to www.mynewsite.com
HTTP::header replace Host "www.mynewsite.com"
} else {
HTTP::redirect "https://[HTTP::host][HTTP::uri]"
}
}
iRule 2
when HTTP_REQUEST {
look for the second string in the data group and redirect
set newURI [findclass [HTTP::uri] $::newURI-Datagroup " "]
if { "" ne $newURI } {
HTTP::redirect "https://www.mynewsite.com/$newURI"
}
}
- DM_5174NimbostratusI was wondering what I am doing wrong here...if you look at the results, I get a "double forward slash" after the redirect completes.data group string parameter:
when HTTP_REQUEST { look for the second string in the data group set newURI [findclass [HTTP::uri] $::URI-datagroup" "] if { "" ne $newURI } { HTTP::redirect "http://www.mysite.com/$newURI" } else { HTTP::redirect "https://[HTTP::host][HTTP::uri]" } }
- hooleylistCirrostratusYou can avoid this by removing the forward slash between .com and $newURI:
- DM_5174NimbostratusThanks Aaron, I will give that a try...How about merging the two irules into one? Can you
- hooleylistCirrostratusYou have three main actions from the two iRules:
- DM_5174NimbostratusHi Aaron,
- hooleylistCirrostratusSo maybe something like this?
when HTTP_REQUEST { Check if the Host is www.mysite.com if { [string tolower [HTTP::host]] eq "www.mysite.com"} { Rewrite the Host header to www.mynewsite.com HTTP::header replace Host "www.mynewsite.com" } else { look for the second string in the data group and redirect set newURI [findclass [HTTP::uri] $::newURI-Datagroup " "] if { "" ne $newURI } { HTTP::redirect "https://www.mynewsite.com$newURI" } else { HTTP::redirect "https://[HTTP::host][HTTP::uri]" } } }
- DM_5174Nimbostratus
- hooleylistCirrostratusYeah, you'll need the leading forward slash on the second field of the datagroup entries. Can you log the mapping in the iRule and reply with the output from /var/log/ltm?
when HTTP_REQUEST { Check if the Host is www.mysite.com if { [string tolower [HTTP::host]] eq "www.mysite.com"} { Rewrite the Host header to www.mynewsite.com HTTP::header replace Host "www.mynewsite.com" } else { look for the second string in the data group and redirect set newURI [findclass [HTTP::uri] $::newURI-Datagroup " "] if { "" ne $newURI } { log local0. "Mapped [HTTP::uri] to $newURI" HTTP::redirect "https://www.mynewsite.com$newURI" } else { HTTP::redirect "https://[HTTP::host][HTTP::uri]" } } }
- DM_5174NimbostratusHi Aaron,
- hooleylistCirrostratusCan you email me and we can try to solve this a little quicker? My address is my first name at f5.com.
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