Forum Discussion
HOST and partial path rewrite
Hi I am new to F5 and am trying to do a URL rewrite a chunk of the URL. I think I am on the right track but I just cannot make it work. Any help is really appreciated.
I just want to replace any request that contains the below retaining the remainder of the URL represented by *
with
http://10.10.10.10:9000/files/*
He is my effort at achieving this.
when HTTP_REQUEST { if { [HTTP::uri] starts_with "/info"}{ HTTP::redirect "http://[string map {https://my.server.net/info http://10.10.10.10:9000/jenkins_files} [string tolower[HTTP::host]][HTTP::uri]]" } }
10 Replies
- kolom
Altostratus
Hello CraigyB, Try using the following iRule.
when HTTP_REQUEST { if { ( [string tolower [HTTP::uri]] starts_with "/info" ) } { set uri [HTTP::uri [string map {"/info" "/files"} [HTTP::uri]]] HTTP::redirect "https://[HTTP::host]$uri" } }- CraigyB_172365
Nimbostratus
Hi Kolom, appreciate your input, which parts do i replace with destination host name and port number?
- kolom
Altostratus
i've tested the following and it's working fine.
when HTTP_REQUEST if { ( [string tolower [HTTP::uri]] starts_with "/info" ) } { set newUri [string map [list "info" "files"] [HTTP::uri]] HTTP::redirect "http://[HTTP::host]$newUri" }if you want to replace the host/port , change the redirection part from HTTP::redirect "http://[HTTP::host]$newUri" to HTTP::redirect "http://10.10.10.10:9000$newUri"
- kolom_265617
Cirrostratus
Hello CraigyB, Try using the following iRule.
when HTTP_REQUEST { if { ( [string tolower [HTTP::uri]] starts_with "/info" ) } { set uri [HTTP::uri [string map {"/info" "/files"} [HTTP::uri]]] HTTP::redirect "https://[HTTP::host]$uri" } }- CraigyB_172365
Nimbostratus
Hi Kolom, appreciate your input, which parts do i replace with destination host name and port number?
- kolom_265617
Cirrostratus
i've tested the following and it's working fine.
when HTTP_REQUEST if { ( [string tolower [HTTP::uri]] starts_with "/info" ) } { set newUri [string map [list "info" "files"] [HTTP::uri]] HTTP::redirect "http://[HTTP::host]$newUri" }if you want to replace the host/port , change the redirection part from HTTP::redirect "http://[HTTP::host]$newUri" to HTTP::redirect "http://10.10.10.10:9000$newUri"
- Lee_Sutcliffe
Nacreous
You can try this iRule - I've written it without the redirect as I presume you want to rewrite the header and URI on the fly - a redirect to a private IP may cause issues if accessing over the internet? Please correct me if not. I've also rewritten the host header using the selected back-end server IP and port you connect to, rather than hard code the IP addresses - this can be changed if needs be Let me know how you get on
when HTTP_REQUEST { if {[HTTP::uri] starts_with "/info"} { set newUri [string map [list "info" "files"] [HTTP::uri]] HTTP::header replace Host "[LB::server addr]:[LB::server port]" HTTP::uri $newUri } }Cheers Lee
- Stanislas_Piro2
Cumulonimbus
Hi,
to do it, no need to create irules.
there is a profile named "rewrite profile" which can do it. create one rewrite profile in URI translation mode, then create one rule with:
- client URI: https://my.server.net/info/
- server URI : http://10.10.10.10:9000/files/
- nitass
Employee
I just need to redirect / rewwrite requests that come in to F5-VIP-Jenkins/info to jenkins-server:9000/jenkins_info. while still persisting any additional path that is supplied. So F5-VIP-Jenkins/info/project1 would redirect to jenkins-server:9000/jenkins_info/project1.
just another example
e.g.
// config root@(ve13a)(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 } translate-address enabled translate-port enabled vs-index 17 } root@(ve13a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm pool foo ltm pool foo { members { 200.200.200.101:9000 { address 200.200.200.101 } } } root@(ve13a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm rule qux ltm rule qux { when HTTP_REQUEST_RELEASE { if { [HTTP::uri] starts_with "/info/" } { HTTP::host "[LB::server addr]:[LB::server port]" HTTP::uri [string map {"/info/" "/jenkins_info/"} [HTTP::uri]] } } } // test [root@ve13a:Active:In Sync] config ssldump -Aed -nni 0.0 port 80 or port 9000 New TCP connection 1: 172.28.24.1(42574) <-> 172.28.24.10(80) 1515777465.5177 (0.0006) C>S --------------------------------------------------------------- GET /info/project1/helloworld HTTP/1.1 User-Agent: curl/7.29.0 Host: 172.28.24.10 Accept: */* --------------------------------------------------------------- New TCP connection 2: 200.200.200.14(3889) <-> 200.200.200.101(9000) 1515777465.5189 (0.0011) C>S --------------------------------------------------------------- GET /jenkins_info/project1/helloworld HTTP/1.1 User-Agent: curl/7.29.0 Host: 200.200.200.101:9000 Accept: */* --------------------------------------------------------------- - BigD_300005
Cirrostratus
Check out F5's LTM > Policies instead of creating an iRule. You can do all this in the GUI.
Create a new policy, name it, then create a rule within the policy "Create policy" button, do all your rules here. URI and redirect changes. Then go to your VIP, resource tab, apply the policy.
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