Forum Discussion
Kamila_124825
Nimbostratus
May 29, 2013Redirect to host port
Hi,
I want to create iRule with redirection. Something like this -> Pool under dns name mysite.com:80 should route members HOST:8080/test/
is the iRule like this will work?? ->
when HTTP_REQUEST {
set host [HTTP:host]
set uri [HTTP:uri]
set port 8080
HTTP::redirect "http://$host:$port$uri/test"
}
6 Replies
- Kevin_Stewart
Employee
If you physically redirect the user to port 8080 you'll need a VIP that's listening on port 8080. If that's NOT what you want (you have a port 80 VIP and pool members listening on port 8080), and you just want to change the Host header to reflect this (internal) port and also change the URI, then something like this might work:when HTTP_REQUEST { if { not ( [string tolower [HTTP::uri]] starts_with "/test" ) } { HTTP::redirect "http://[HTTP::host]/test[HTTP::uri]" } else { HTTP::header replace Host "[HTTP::host]:8080" } }
The above physically redirects the user (via 302) to "/test" if the original URI doesn't start with the "/test". It also adds the requested URI to the end of the path (ex. /myrequest = /test/myrequest). Not sure if you needed that part. The Host header is then replaced with the same Host header plus the ":8080" port (ex. mysite.com = mysite.com:8080). I'm assuming that since port 80 is the default for HTTP, the user request won't actually contain ":80". - Kamila_124825
Nimbostratus
but when I write mysite.com then will not redirect me to 8080 port.
only to http://host/test
I need to add :8080?when HTTP_REQUEST { if { not ( [string tolower [HTTP::uri]] starts_with "/test" ) } { HTTP::redirect "http://[HTTP::host]:8080/test[HTTP::uri]" } else { HTTP::header replace Host "[HTTP::host]:8080" } } - Kevin_Stewart
Employee
This all depends on your configuration. Do you want to physically redirect users to a VIP that is listening on port 8080? Or do you have a single port 80 VIP? - Kamila_124825
Nimbostratus
Hmm.. VIP is listening on port 80. but I think I don't need a physically redirection, because a member register in pool with 8080 port. So maybe will work only this:when HTTP_REQUEST { if { not ( [string tolower [HTTP::uri]] starts_with "/test" ) } { HTTP::redirect "http://[HTTP::host]/test[HTTP::uri]" } }
What do you think? - Kevin_Stewart
Employee
Again, completely depends on your configuration. The HTTP::redirect command issues a physical redirect (via 302 message) to the client. This is what you're doing in your last iRule if the URI doesn't start with "/test". As for the port 8080 business, your pool should define the back end servers by IP and this port. Port translation on the VIP will take care of sending traffic to port 8080. If, however (and this is rare but it happens), the server expects to see this port in the request Host header (ex. Host = www.example.com:8080), then you need to modify the Host header on the way in. - Kamila_124825
Nimbostratus
Thank you. Everything is clear now.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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