Forum Discussion
iRule for URL rewriting
Hi All,
I have a query on URL rewriting. Here is the scenario:
abc.externalurl.com/something/action?key1=value1 --> F5 --> something.internalurl.com/action?key1=value1
secondhost.com is internal URL not available to the public, so I think it should be host replacement rather than redirect.
- ssievers_87378Nimbostratus
Maybe something like this:
when HTTP_REQUEST { set val1 [getfield [HTTP::uri] "/" 1] set val2 [getfield [HTTP::uri] "/" 2] set my_location "$val1.internalurl.com/$val2" HTTP::Respond 301 Location "$my_location" log local0. "Redirecting to $my_location" }
Cheers.
- ssievers_87378Nimbostratus
Sorry - I missed the "http://" on the redirect.
set my_location "http://$val1.internalurl.com/$val2"
- Stanislas_Piro2Cumulonimbus
Hi,
if you are in version 11.4.0 or above, you can use a rewrite profile:
- clientside : http://abc.externalurl.com/something/
- serverside : http://something.internalurl.com/
or use the irule:
when HTTP_REQUEST { set val1 [getfield [HTTP::uri] "/" 1] HTTP::host "$val1.internalurl.com" HTTP::uri [string map "$val1 /" [HTTP::uri]] }
- dihris_116090Nimbostratus
Does the iRule change if the VS is HTTPS ? Also as the internalurl.com should be visible to the end user will the iRule take care for the http_respond back and remap the respond back to abc.externalurl.com?
The reason I had in mind iRule is that it's more flexible and adding another context later would not be a problem. Where with clientside/serverside rewrite profile is static.
- Stanislas_Piro2CumulonimbusThe ltm does not select destination server base on his hostname. you must create one pool for each internal server. so you must change configuration for each new internal service to publish and assign it to the external URL.
- dihris_116090Nimbostratus
Sorry - I made a typo. "... as the internalurl.com should NOT be visible to the end user will the iRule take care for the http_respond back and remap the respond back to abc.externalurl.com?"
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