Forum Discussion
dihris_116090
May 28, 2016Nimbostratus
HTTP Rewrite header + pool based on URI
Hi,
I need to forward traffic from external URL to one of our internal servers based on URI. That has to be transparent for the browser with no redirect messages 3xx.
Searching in the forum and u...
- May 28, 2016
Hi,
here an rule example :
when RULE_INIT { set external_hostname "externalsite.com" set internal_hostname "internalsite.com" } when CLIENT_ACCEPTED { set default_pool [LB::server pool] } when HTTP_REQUEST { Disable the stream filter for requests STREAM::disable Remove this header to prevent server from compression response HTTP::header remove Accept-Encoding if { ([string tolower [HTTP::path]] eq "/foobar") } { HTTP::host [string map {$external_hostname $internal_hostname} [HTTP::host]] pool internal_pool } else { pool $default_pool } } when HTTP_RESPONSE { Rewrite the Location header for redirects if { [HTTP::header exists Location] }{ HTTP::header replace Location [string map {$external_hostname $internal_hostname} [HTTP::header Location]] } Rewrite the response content using a stream profile if it is text if { [HTTP::header Content-Type] contains "text" } { Set the stream expression with the find/replace strings STREAM::expression "@xyz.company.com@abc.company.com@" Enable the stream filter STREAM::enable } }
Yann_Desmarest
May 28, 2016Cirrus
Hi,
In the HTTP_REQUEST event, try to replace this :
HTTP::host [string map {$external_hostname $internal_hostname} [HTTP::host]]
by
HTTP::header replace "Host" [string map "$external_hostname $internal_hostname" [HTTP::host]]
- Yann_DesmarestMay 28, 2016Cirrusor use : HTTP::header replace "Host" [string map -nocase [list $external_hostname $internal_hostname] [HTTP::host]]
- Yann_DesmarestMay 28, 2016CirrusThe issue is the support for variables in the string map
- dihris_116090May 30, 2016NimbostratusIn both cases I'm getting TCL error: err tmm1[32619]: 01220001:3: TCL error: /Common/test_3 - can't read "external_hostname": no such variable while executing "string map "$external_hostname $internal_hostname" [HTTP::host]" ==================== err tmm1[32619]: 01220001:3: TCL error: /Common/test_3 - can't read "external_hostname": no such variable while executing "list $external_hostname $internal_hostname" I did verify that the variables I set when initiating the iRule do match. My internal host does have a bit non standard name: foo-bar-baz.qux.mycompany.io can that be creating an issue?
- dihris_116090May 30, 2016NimbostratusI replaced the variables with hard coded fqdns for the internal and external host and now I see header being rewritten. I also see the right pool being selected, though I get 302 response comes from a node that is a member of the default pool associated to the VS instead from a member of selected pool
- Yann_DesmarestMay 30, 2016CirrusDid you configure persistence profile ? You may also need to activate a oneconnect profile
- dihris_116090May 31, 2016NimbostratusI made it working with your code, but ultimately decided to go with ProxyPass iRule published by Kirk Bauer. One thing that I cannot figure it out is I'd like to use SNAT and for that I need to create data group (internal string type). Based on the ProxyPass script all entries should be separate by space though when creating data group (internal) it does not let me select my own space divider. When trying to configure external data group if I select space divider different than ":=" it does not let me do it. Any thoughts on that?
- Yann_DesmarestJun 01, 2016CirrusHi, in the internal datagroup, you set the pool name in the string field and the snat in the value field. The delimiter will be added automatically ":=" when you add the entry. You need to add an entry (string/value) for each snat entry
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