Forum Discussion
kc2kth_49679
Nimbostratus
Feb 06, 2009Rewrite host and URI, then redirect
I thought I was pretty close on this one, but I can't quite get it to work. I need to rewrite a portion of a URI (drop part of the path and change the name of the page), change the host name, t...
hoolio
Cirrostratus
Feb 16, 2009You're very close. To update the URI without a redirect you can use HTTP::uri. You'd use HTTP::header replace for the Host header because for whatever reason, you cannot rewrite the host using HTTP::host "newhost".
when HTTP_REQUEST {
switch [string tolower [HTTP::host]] {
"host.domain.com" {
HTTP::uri [string map {"/string" "/newstring" "page.jsp" "newpage.aspx"} [HTTP::uri]]
pool pool_name
}
default {
reject
}
}
}
The values for HTTP::uri and HTTP::host are cached within the same rule and event so logging the updated value won't show the change. But it is actually changed in the request sent to the server. If you'd like to verify this, you can add a second HTTP_REQUEST event which runs after the default priority HTTP_REQUEST event:
when HTTP_REQUEST {
log local0. "Priority 500: [IP::client_addr]:[TCP::client_port]: Original request to [HTTP::host][HTTP::uri]"
switch [string tolower [HTTP::host]] {
"host.domain.com" {
HTTP::uri [string map {"/string" "/newstring" "page.jsp" "newpage.aspx"} [HTTP::uri]]
pool pool_name
}
default {
reject
}
}
}
when HTTP_REQUEST priority 501 {
log local0. "Priority 501: [IP::client_addr]:[TCP::client_port]: Updated request to [HTTP::host][HTTP::uri]"
}
Aaron
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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