Forum Discussion
Redirect / Rewrite iRule
Hi,
I am trying to achieve something quite straight forward with an iRule but struggling to get this to work.
The requirement is this: I want an iRule to both redirect and rewrite the URL at the requesting browser. For example, a request to http://www.new.com should redirect to http://www.old.com/vs, but leave (or re-write) the address as http://www.new.com.
I have looked at Colin Walker’s “Redirects, Rewrites and App Transfers via iRules” article, from which I’ve put together the following:
when HTTP_REQUEST {
set newURI "/vs"
HTTP::uri $newURI
HTTP::header replace "Host" "old.com"
}
when HTTP_RESPONSE {
log local0. "Response: [HTTP::host]"
}
The best I get is the following error from Firefox: The connection to the server was reset while the page was loading.
Interestingly, I never see the HTTP_RESPONSE entry in the LTM log.
Using the HTTP::redirect command gives what I’m after as far as redirection is concerned, but places the redirected to URL in the browser address bar.
So, what I’m after is an iRule to redirect but also allow me to manipulate the URL as seen at the browser.
Any help appreciated.
Mark.
Ps: Relatively new to F5s; really new to iRules!
5 Replies
- nathe
Cirrocumulus
MarkB
Wouldn't the host be www.old.com? I've also removed the variable set as it adds an extra process and you're not making many references to it so I wouldn't bother. Just my 2pence.
Try this:when HTTP_REQUEST { HTTP::header replace "Host" "www.old.com" HTTP::uri "/vs" } when HTTP_RESPONSE { log local0. "Response: [HTTP::host]" }
HTH,
N - What_Lies_Bene1
Cirrostratus
You won't see a response log entry as the real server is rejecting the connection, perhaps due to the missing www.
Note, just to clarify the language, that this rule is rewriting, not redirecting.
Are there any other paths to consider other than /vs? This part might need to be a bit more intelligent. - MarkB_125162
Nimbostratus
Guys,
Thanks for your suggestions and help here – still no joy. Fundamentally, I don’t think there’s anything wrong with what I’m trying. One for the server teams to see if they can offer any assistance.
Thanks again, Mark. - What_Lies_Bene1
Cirrostratus
You're welcome. Do post back if you find a solution. Cheers - Arie
Altostratus
Could you configure the web server so it responds to the new host on the instance for the old one? In that case you wouldn't need to do anything on the LTM.
If the folder structure is different you might also be able to make the /vs folder the root of the instance.
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