Forum Discussion
HTTP Redirect and cut out URL
client request contain url "mvpvote",for example,request http://www.test.com/mvpvote/xxxxx,I want redirect URL to http://www.test.com:8080/xxxxx, I don't how 。
12 Replies
- CANSTAYN569_243
Nimbostratus
when HTTP_REQUEST {
if {[HTTP::uri] starts_with "/mvpvote"} {
pool Pool_Test.com:8080
}
}
So i would create a new pool that has the same servers but the port is 8080. I would redirect the requests to that pool. Also since i did not modify the full uri, you would need to change the path to content. (You would need to put it below mvpnote folder)
Regards
- denny_65237
Nimbostratus
thanks ,But how to cut /mvpvote/xxxx to /xxxx
- CANSTAYN569_243
Nimbostratus
As a quick solution, instead of cutting the url i would change the Path of content under iis or whatever web server you are using. I would add another folder named mvpvote
- CANSTAYN569
Nimbostratus
when HTTP_REQUEST {
if {[HTTP::uri] starts_with "/mvpvote"} {
pool Pool_Test.com:8080
}
}
So i would create a new pool that has the same servers but the port is 8080. I would redirect the requests to that pool. Also since i did not modify the full uri, you would need to change the path to content. (You would need to put it below mvpnote folder)
Regards
- denny_65237
Nimbostratus
thanks ,But how to cut /mvpvote/xxxx to /xxxx
- CANSTAYN569
Nimbostratus
As a quick solution, instead of cutting the url i would change the Path of content under iis or whatever web server you are using. I would add another folder named mvpvote
- Jinshu
Cirrus
Try something like below one..
when HTTP_REQUEST { if {[string tolower [HTTP::uri]] starts_with "/mvpvote"}{ set newuri [string map -nocase {"/mvpvote" ""}[HTTP::uri]] HTTP::redirect "http://[HTTP::Host]:8080$newuri" } }-Jinshu
- The_Y
Cirrus
Jinshu irule will work great but if you want the user to see the new url and add a redirect code then you might have to add a few things to it.
when HTTP_REQUEST { if {[string tolower [HTTP::uri]] starts_with "/mvpvote"}{ set newuri [string map -nocase {"/mvpvote" ""}[HTTP::uri]] HTTP::redirect "http://[HTTP::Host]$newuri" } } - VernonWells
Employee
There are two drawbacks with the use of
, in this case. Firstly, it will replaces all instances of "/mvpvote", even if it happens more than once in the path (or if you're usingstring map
, in the entire length of the Request Target). Secondly, it would replace, for example, "/mvpvote2/" with "2/".HTTP::uriThe following solution should be more correct, and as a bonus, better performing (though not tested!):
when HTTP_REQUEST { switch -glob [HTTP::path] { "/mvpvote" { HTTP::respond 301 Location "http://[HTTP::host]/[HTTP::query]" } "/mvpvote/*" { HTTP::respond 301 Location "http://[HTTP::host][substr [HTTP::uri] 8]" } } }- denny_65237
Nimbostratus
Yes,this is more exactly.thank you .I will test it.
- Vernon_97235Historic F5 Account
There are two drawbacks with the use of
, in this case. Firstly, it will replaces all instances of "/mvpvote", even if it happens more than once in the path (or if you're usingstring map
, in the entire length of the Request Target). Secondly, it would replace, for example, "/mvpvote2/" with "2/".HTTP::uriThe following solution should be more correct, and as a bonus, better performing (though not tested!):
when HTTP_REQUEST { switch -glob [HTTP::path] { "/mvpvote" { HTTP::respond 301 Location "http://[HTTP::host]/[HTTP::query]" } "/mvpvote/*" { HTTP::respond 301 Location "http://[HTTP::host][substr [HTTP::uri] 8]" } } }- denny_65237
Nimbostratus
Yes,this is more exactly.thank you .I will test it.
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