Forum Discussion
Need help on wildcard redirect iRule
We need to an iRule to redirect traffic from
https://abc.test.com/*
https//*.abc.test.net
Here is the iRule
when HTTP_REQUEST { scan [HTTP::uri] %[^.]%[^.] prefix uri log local0. "$uri" set original_uri [HTTP::uri] set append [getfield [string range [HTTP::uri] 1 end] "$prefix" 1] if {[HTTP::host] equals "abc.test.com" } { set host [string map {abc.test.com abc.test.net} [HTTP::host]] HTTP::header replace Host $append.$host$uri } } when HTTP_RESPONSE { if { [HTTP::header exists Location] } { regsub "$append.abc.test.net" [HTTP::header Location ] "abc.test.com" newlocation HTTP::header replace Location $newlocation$original_uri } }
Can you please let me know what we did wrong?
Thank you very much in advance!
William Sun
2 Replies
- Arie
Altostratus
Try this instead.
when HTTP_REQUEST { if { [HTTP::host] equals "abc.test.com" } { HTTP::redirect "https:/[HTTP::path].abc.test.net" } }Note: I've omitted a slash from "https://" since the path will always start with a slash. That'll provide the second one for "https://".
- nitass
Employee
not sure if i understand the question correctly.
e.g.
config root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm virtual bar ltm virtual bar { destination 172.28.24.10:80 ip-protocol tcp mask 255.255.255.255 pool foo profiles { http { } tcp { } } rules { qux } source 0.0.0.0/0 source-address-translation { type automap } vs-index 41 } root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm pool foo ltm pool foo { members { 200.200.200.101:80 { address 200.200.200.101 } } } root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm rule qux ltm rule qux { when RULE_INIT { set static::org_host "abc.test.com" set static::new_host "abc.test.net" } when HTTP_REQUEST { if { [scan [HTTP::uri] {/%[^/]} prefix] != 1 } { Exit if no prefix return } if { [HTTP::host] equals $static::org_host } { Insert prefix to Host header HTTP::header replace Host "${prefix}.${static::new_host}" Delete prefix from URI HTTP::uri [string map [list "/${prefix}/" "/" "/${prefix}" "/"] [HTTP::uri]] } } when HTTP_RESPONSE { if { [HTTP::header exists Location] } { Extract prefix from Location header scan [URI::host [HTTP::header Location]] {%[^.]} prefix Move prefix from Host to URI in Location header HTTP::header replace Location [string map [list "${prefix}.${static::new_host}/" "${static::org_host}/${prefix}/"] [HTTP::header Location]] } } } trace [root@ve11a:Active:In Sync] config ssldump -Aed -nni 0.0 port 80 New TCP connection 1: 172.28.24.1(48014) <-> 172.28.24.10(80) 1404023233.7475 (0.0016) C>S --------------------------------------------------------------- HEAD /something/bhabhabha HTTP/1.1 User-Agent: curl/7.15.5 (i686-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5 Accept: */* Host: abc.test.com --------------------------------------------------------------- New TCP connection 2: 200.200.200.14(48014) <-> 200.200.200.101(80) 1404023233.7619 (0.0141) C>S --------------------------------------------------------------- HEAD /bhabhabha HTTP/1.1 User-Agent: curl/7.15.5 (i686-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5 Accept: */* Host: something.abc.test.net --------------------------------------------------------------- 1404023233.7757 (0.0138) S>C --------------------------------------------------------------- HTTP/1.1 302 Found Date: Sun, 29 Jun 2014 06:15:51 GMT Server: Apache/2.2.3 (CentOS) Location: http://something.abc.test.net/somethingelse/bhabhabha Content-Type: text/html; charset=iso-8859-1 --------------------------------------------------------------- 1404023233.7759 (0.0283) S>C --------------------------------------------------------------- HTTP/1.1 302 Found Date: Sun, 29 Jun 2014 06:15:51 GMT Server: Apache/2.2.3 (CentOS) Location: http://abc.test.com/something/somethingelse/bhabhabha Content-Type: text/html; charset=iso-8859-1 ---------------------------------------------------------------
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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