Forum Discussion
Please help with iRule rewrite while keeping original url for external domain
Hello everyone,
Having a tough time finding a correct answer to this. I have seen very similar answers but nothing that does quite what I am asking. I am new to iRules so be kind. I have a client with the following requirements.
- When connecting to abc.xyz flow is as normal.
- When connecting to abc.xyz/example they should be redirected to abc.external.org website while retaining the original URL that is locally hosted.
The external website is not hosted locally but is just an external resource the client has an association with. I have looked for an answer all weekend with no success other than being able to get the redirect to work properly.
What I have below is supposed to keep the original URL but it does not. It just does the redirect. Any help would be greatly appreciated.
when HTTP_REQUEST {
if { [string tolower [HTTP::host]] equals "abc.xyz" and [string tolower [HTTP::uri]] starts with "/example" } {
HTTP::respond 301 noserver Location "abc.external.xyz"
}
}
I have also tried changing the HTTP::header on the HTTP_RESPONSE but that just gives me a 404 error with the following in the address bar "abc.xyz/abc.external.xyz".
I have also seen suggestions of using rewrite profiles but that doesn't seem to do what I want either and can't find any real examples of them. Again, any help would be appreciated.
Thank you!
Jonathan
- JonathanW_38552
Nimbostratus
Is there no one that can help with this? It would be greatly appreciated.
- Dave_McCauley_3
Cirrostratus
Add the URI to the redirect:
when HTTP_REQUEST { if { [string tolower [HTTP::host]] equals "abc.xyz" and [string tolower [HTTP::uri]] starts with "/example" } { HTTP::respond 301 noserver Location "https://abc.external.xyz[HTTP::uri]" } }
- JonathanW_38552
Nimbostratus
Thank you Dave for your response. It still gives me the same 404 error with both URL's in the address bar.
Jonathan
Hi Jonathan,
You can try creating an FQDN node and pool containing the external website and then using an iRule to replace the HTTP host header while not modifying the URI.
Try this (substitute your own values) and let me know if it works:
create ltm node www.foo.net fqdn { name www.foo.net interval ttl } create ltm pool POOL-www.foo.net members add { www.foo.net:80 } when HTTP_REQUEST { if { [string tolower [HTTP::host]] equals "abc.net" && [string tolower [HTTP::uri]] starts_with "/example" } { HTTP::header replace host "www.foo.net" pool POOL-www.foo.net snat automap } }
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