Forum Discussion
iRule to modify the URI without a client redirect
Say I have a site called https://la.mysite.com (10.1.1.100), which is not currently served by F5. I want clients who browse to https://china.mysite.com, which is set up as a VS on F5 to see the content located at https://la.mysite.com/documents/china.pdf. Except that I want the browser to display china.mysite.com/documents/china.pdf in the address bar.
I've tried these iRules, but each one produces the same result. A packet capture shows a HTTP 302 coming from the VS, and then the browser address bar changes to la.mysite.com instead of staying china.mysite.com. What am I doing wrong?
when HTTP_REQUEST {
if { [HTTP::host] equals "china.mysite.com"} { HTTP::header replace Host "la.mysite.com" }
}
when HTTP_REQUEST {
if { [HTTP::host] equals "china.mysite.com"} { HTTP::path "https://la.mysite.com" } }
You may want to look at this page:
https://devcentral.f5.com/wiki/iRules.HTTP__uri.ashx
Using a redirect will change the URL on the browser.
Changing the Host header only affects what the server gets.
You will need the IP address of la.mysite.com, say it is 1.2.3.4
You will need an irule like this:
when HTTP_REQUEST { if { [HTTP::uri] equals "/" } { the node command directs the request to the server whether or not it is behind the BigIP. Make sure the BigIP has a route to that server. node 1.2.3.4 In case you don't have SNAT on the virtual, you may need it here. snat automap In case the server complains, set the host header. HTTP::header replace Host "la.mysite.com" Finally change the URI while on its way to server. HTTP::uri /documents/china.pdf } }Here is the page for the SNAT command:
https://devcentral.f5.com/wiki/iRules.snat.ashx
Here is the page for the node command:
4 Replies
- Richard_Jones
Nimbostratus
Let me see if I have your plan correct:
- User connects to https://china.mysite.com/
- User gets redirected to https://china.mysite.com/documents/china.pdf
- User requests that URL, which causes the BIG-IP to send the request to a pool for the la.mysite.com server.
I think this might be what you want:
when HTTP_REQUEST { if {[HTTP::host] equals "china.mysite.com"}{ if {[HTTP::uri] equals "/"}{ HTTP::redirect "/documents/china.pdf" } elseif {[HTTP::uri] equals "/documents/china.pdf"}{ HTTP::host "la.mysite.com" pool la_mysite_pool } } }What is does:
If the host equals china.mysite.com and the URI equals /, redirect to /documents/china.pdf. If the host equals china.mysite.com and the URI equals /documents/china.pdf, change the host header in the HTTP request to la.mysite.com and send the request to the pool that contains the server hosting la.mysite.com.
Make sense?
- John_Alam_45640Historic F5 Account
You may want to look at this page:
https://devcentral.f5.com/wiki/iRules.HTTP__uri.ashx
Using a redirect will change the URL on the browser.
Changing the Host header only affects what the server gets.
You will need the IP address of la.mysite.com, say it is 1.2.3.4
You will need an irule like this:
when HTTP_REQUEST { if { [HTTP::uri] equals "/" } { the node command directs the request to the server whether or not it is behind the BigIP. Make sure the BigIP has a route to that server. node 1.2.3.4 In case you don't have SNAT on the virtual, you may need it here. snat automap In case the server complains, set the host header. HTTP::header replace Host "la.mysite.com" Finally change the URI while on its way to server. HTTP::uri /documents/china.pdf } }Here is the page for the SNAT command:
https://devcentral.f5.com/wiki/iRules.snat.ashx
Here is the page for the node command:
- calicolin_13604
Nimbostratus
Hi folks, Thanks for your suggestions! I've tried them all and have learned a lot in the process. The good news is that John's irule appears to work perfectly. The browser is still receiving an HTTP re-direct, but it appears to originate from the server itself, not from F5. I know this because I tried the same iRule against a different web server and it retained the masked URL, and appended the URI as desired after the /. So this is something the server team must address. This is an extremely useful irule for us.
Thanks
- PSPK
Nimbostratus
Thanks for the discussion on the same issue I am facing
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