Forum Discussion
The question about the rewriting URI based on source IP
Hi all, I Have a Standard VS with a http profile and the service domain is "http://www.abc.com" I want to rewriting or replacing the URI based on source IP.
For example,
-
When the request with 10.10.10.0/24 is arrived, I want to change "http://www.abc.com" to "http://www.abc.com" or forward the default pool.
-
When the request with 20.20.20.0/24 is arrived, I want to change "http://www.abc.com" to "http://www.abc.com/test1"
-
When the request with the remaining IPs is arrived, I want to change "http://www.abc.com" to "http://www.abc.com/test2"
I am not consider the redirecting URI, because the users should not notice the above action.
Could you please refer me to share the reference? Please help.
Thank you
4 Replies
Hi! Perhaps something like this?
when HTTP_REQUEST { if { [IP::addr [IP::client_addr] equals 10.10.10.0/24] } { Do nothing to forward to the default pool } elseif { [IP::addr [IP::client_addr] equals 20.20.20.0/24] } { HTTP::uri "/test1" } else { HTTP::uri "/test2" } }/Patrik
If you have any objects, like images or css, in the different subfolders, ie /test1/img/picture.gif, /test2/script.js you might want to try this one:
when HTTP_REQUEST { set uri [string tolower [HTTP::uri]] if { [IP::addr [IP::client_addr] equals 10.10.10.0/24] } { Do nothing to forward to the default pool } elseif { [IP::addr [IP::client_addr] equals 20.20.20.0/24] } { if { not $uri starts_with "/test1" } { HTTP::uri "/test1" } } else { if { not $uri starts_with "/test2" } { HTTP::uri "/test2" } } }Please note that all these uses the default pool, but with different URI's.
/Patrik
- Mia_27938
Nimbostratus
Hi Patrik,
I made a mistake. Purpose has changed.
The condition correctly is the follow.
The service domain originally is "test.abc.com".
-
When the request with 10.10.10.0/24 is arrived, I want to not change "test.abc.com" and forward the default pool.
-
When the request with the remaining IPs is arrived, I want to replace "test.abc.com" to "www.abc.com/go"
I maked the following..I know the following rule is not cool..so hard..
when HTTP_REQUEST { if { [IP::addr [IP::client_addr] equals 10.10.10.0/24] } {
} else { HTTP::header replace Host "www.abc.com/go"
}
}
Thank you
-
Hi!
Everything is hard in the beginning. Keep trying and you'll get there. 🙂
The problem with your rule was this part:
HTTP::header replace Host "www.abc.com/go""www.abc.com" is the host, and "/go" is the URI so you must change them separately.
As per your description, try this one:
when HTTP_REQUEST { if { [IP::addr [IP::client_addr] equals 10.10.10.0/24] } { Do nothing to forward to the default pool } else { Replace the host HTTP::header replace Host "www.abc.com" set [string tolower [HTTP::uri]] Check if the uri start with /go. If not, replace it with /go. if { not $uri starts_with "/go"} { HTTP::uri "/go" } } }Good luck!
/Patrik
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