Forum Discussion
I want to Redirect multiple Sites in a single Irule. please help me with the irule command.
I have mulitple sites where i want my LAN users should not to redirected to https when they use url with http. but when any internet users use http://abc.com than it should redirect to https://abc.com
Can i use the below irule for this.
when HTTP_REQUEST { if {[HTTP::host] equals "abc.com"} { HTTP::redirect "https://abc.com[HTTP::uri]" } }
Now i want to do for multiple sites in same irule can i use another if statement?
49 Replies
- Yann_Desmarest_
Nacreous
Hello,
You can add an if condition
log local0. "Incoming URI = [HTTP::uri]" if { [string tolower [HTTP::uri]] starts_with "/bseu" } { if { [string tolower [HTTP::uri]] equals "/bseu" or [string tolower [HTTP::uri]] starts_with "/bseu/it" } { set uri [HTTP::uri] } else { set uri [string map -nocase {"/bseu" "/sites"} [HTTP::uri]] } log local0. "New URI = $uri" HTTP::uri $uri } }- ShakN_167332
Nimbostratus
when i use this code my redirection is working as expected but stopps working after first time testing. if there any issue with the code. can you please help me.
Hello,
You can add an if condition
log local0. "Incoming URI = [HTTP::uri]" if { [string tolower [HTTP::uri]] starts_with "/bseu" } { if { [string tolower [HTTP::uri]] equals "/bseu" or [string tolower [HTTP::uri]] starts_with "/bseu/it" } { set uri [HTTP::uri] } else { set uri [string map -nocase {"/bseu" "/sites"} [HTTP::uri]] } log local0. "New URI = $uri" HTTP::uri $uri } }- ShakN_167332
Nimbostratus
when i use this code my redirection is working as expected but stopps working after first time testing. if there any issue with the code. can you please help me.
- ShakN_167332
Nimbostratus
this is my irule and applied on vs 443. my /bseu to /sites redirection works first time and next time onwords redirection is not happening.
when RULE_INIT { set static::asitesext "asites.abc.com" set static::asitesint "asites.internet.abc.com" set static::aportalext "aportal.abc.com" set static::aportalint "aportal.internet.abc.com" set static::amyext "amy.abc.com" set static::amyint "amy.internet.abc.com" set static::aextranetext "aextranet.abc.com" set static::aextranetint "aextranet.internet.abc.com" set static::awww "awww.abc.com" } when HTTP_REQUEST { if {[class match [IP::client_addr] equals InternalHosts]} {
HTTP::redirect http://[HTTP::host][HTTP::uri] } else { log local0. "Incoming URI = [HTTP::uri]" if { [string tolower [HTTP::uri]] starts_with "/bseu" } { if { [string tolower [HTTP::uri]] equals "/bseu" or [string tolower [HTTP::uri]] starts_with "/bseu/it" } { set uri [HTTP::uri] } else { set uri [string map -nocase {"/bseu" "/sites"} [HTTP::uri]] } log local0. "New URI = $uri" HTTP::uri $uri }switch -glob -- [string tolower [HTTP::host]] { "asites.abc.com" { HTTP::header replace Host $static::asitesint STREAM::disable } "awww.abc.com" { HTTP::redirect https://aportal.abc.com STREAM::disable } "aportal.abc.com" { HTTP::header replace Host $static::aportalint STREAM::disable } "amy.abc.com" { HTTP::header replace Host $static::amyint STREAM::disable } "aextranet.abc.com" { HTTP::header replace Host $static::aextranetint STREAM::disable } }} } when HTTP_RESPONSE { if {[HTTP::is_redirect] && [string tolower [HTTP::header "Location"]] contains $static::asitesint}{ HTTP::header replace Location [string map "$static::asitesint $static::asitesext" [HTTP::header Location]] STREAM::enable } elseif {[HTTP::is_redirect] && [string tolower [HTTP::header "Location"]] contains $static::aportalint}{ HTTP::header replace Location [string map "$static::aportalint $static::aportalext" [HTTP::header Location]] STREAM::enable } elseif {[HTTP::is_redirect] && [string tolower [HTTP::header "Location"]] contains $static::amyint}{ HTTP::header replace Location [string map "$static::amyint $static::amyext" [HTTP::header Location]] STREAM::enable } elseif {[HTTP::is_redirect] && [string tolower [HTTP::header "Location"]] contains $static::aextranetint}{ HTTP::header replace Location [string map "$static::aextranetint $static::aextranetext" [HTTP::header Location]] STREAM::enable } }
- StephanManthey
Nacreous
Could you please provide the log output by running the following command while testing: tail -f /var/log/ltm - ShakN_167332
Nimbostratus
please find the below output of the log tail -f/var/log/ltm [admin@xyz:Active] ~ tail -f /var/log/ltm | grep test Sep 2 10:37:39 local/tmm info tmm[4924]: Rule test : Incoming URI = /bseu/finance Sep 2 10:37:39 local/tmm info tmm[4924]: Rule test : New URI = /bseu/finance Sep 2 10:38:13 local/tmm info tmm[4924]: Rule test : Incoming URI = /favicon.ico Sep 2 10:38:23 local/tmm info tmm[4924]: Rule test : Incoming URI = /bseu/hr Sep 2 10:38:23 local/tmm info tmm[4924]: Rule test : New URI = /bseu/hr Sep 2 10:38:31 local/tmm info tmm[4924]: Rule test : Incoming URI = /bseu/it Sep 2 10:38:31 local/tmm info tmm[4924]: Rule test : New URI = /bseu/it Sep 2 10:39:08 local/tmm info tmm[4924]: Rule test : Incoming URI = /bseu/bd Sep 2 10:39:08 local/tmm info tmm[4924]: Rule test : New URI = /bseu/bd Sep 2 10:39:21 local/tmm info tmm[4924]: Rule test : Incoming URI = /bseu/rd Sep 2 10:39:21 local/tmm info tmm[4924]: Rule test : New URI = /bseu/rd Sep 2 10:39:54 local/tmm info tmm[4924]: Rule test : Incoming URI = /bseu/procurement Sep 2 10:39:54 local/tmm info tmm[4924]: Rule test : New URI = /bseu/procurement Sep 2 10:40:03 local/tmm info tmm[4924]: Rule test : Incoming URI = /bseu/markets Sep 2 10:40:03 local/tmm info tmm[4924]: Rule test : New URI = /bseu/markets - ShakN_167332
Nimbostratus
Can any one give me alternative code for my requirement.
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