Forum Discussion
Cindy_127211
Nimbostratus
Aug 16, 2006Rewriting Hostname & URI on HTTP_Request without a 'redirect'
I would like to 'rewrite' the following hostname/uri:
http://www.website1.com/index.php?cid=1234
to
http://www.website2.com/app1/index.php?cid=1234
without using a 'redirect'. It is important on this 'rewrite' that the variable information (cid=1234) get carried over. However, I've only been able to do this with a 'redirect'. I'd prefer to just 'rewrite' the hostname/url;however, as the application code resides on the same server.
How can I make a 'rewrite' (versus a redirect) work in this scenario? Also, I 'threw' in the HTTP::header replace HOST statement...but, don't know if it is really needed.
when HTTP_REQUEST {
if {[HTTP::uri] starts_with "/index.php"} {
set newuri "/livestrongportfolios[HTTP::uri]"
set newhost "www.americancentury.com"
HTTP::header replace HOST $newhost
HTTP::redirect "http://$newhost$newuri"
}
else {
HTTP::redirect "https://[HTTP::host][HTTP::uri]"
}
}
- JRahm
Admin
You can set the uri and host directly on a request, and forward to a configured pool internal to the system without issuing a redirect:when HTTP_REQUEST { if {[HTTP::uri] starts_with "/index.php"} { HTTP::uri "/app1[HTTP::uri]" HTTP::host "www.website2.com" pool your_pool_name } else { HTTP::redirect "https://[HTTP::host][HTTP::uri]" } }
- Cindy_127211
Nimbostratus
I have tried the fomrat that you suggested below, but it doesn't work. The rules editor shows a 'red' circle next to the HTTP::host statement and I am getting the following error in the 'ltm' log. - JRahm
Admin
Sorry about that..I thought setting the host with that command was valid. Try this (I'm assuming you have a pool assigned in the vip?):when HTTP_REQUEST { if {[HTTP::uri] starts_with "/index.php"} { log "Requested URL is [HTTP::host][HTTP::uri]" HTTP::uri "/livestrongportfolios[HTTP::uri]" HTTP::header replace "Host" "www.americancentury.com" log "New URL is [HTTP::host][HTTP::uri]" } else { HTTP::redirect "https://[HTTP::host][HTTP::uri]" } }
when HTTP_REQUEST_SEND { log local0. "New URL is [HTTP::host][HTTP::uri]" }
- Cindy_127211
Nimbostratus
Thanks for your help with this. I am now able to resolve the 'host' name to the new name with the following statement. - Cindy_127211
Nimbostratus
Sorry....I should add that the HTTP::uri is not getting reset to the new URI. - There were some caching optimizations put in with regards to internal variables such that if you set the value of one with the command (ie. "HTTP::uri /foo"), trying to use that value will still display the original value before the assignment.
- JRahm
Admin
do a tcpdump on the serverside vlan and look for the URI. At the command line, issue the command below and then run your test. Ctrl-C will kill the process when your test is done.
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