Need assistance rewriting a hostname and appending a uri.
I am having trouble rewriting a hostname and appending a url.
Below is a sample of what I am trying to do:
The user is going to https://apples.com. I need to send the user to https://lemons.com without the customer seeing "lemons.com" in their browser via a redirect.
Also, if the user enters https://apples.com, I need to send them to https://lemons.com/fruit/TREE.html. If they enter https://apples.com/fruit/TREE.html, I need to redirect them to https://lemons.com/fruit/TREE.html.
Below is currently what I have as an iRule. If the user enters in the full url - https://apples.com/fruit/TREE.html, the site works. However, if they enter anything else, such as https://apples.com, they receive a blank page.
when HTTP_REQUEST {
if { [HTTP::uri] equals "/" } {
HTTP::header replace host "lemons.com" HTTP::uri "/fruit/TREE.html" } elseif { [HTTP::uri] equals "/TREE.HTML" } { HTTP::header replace host "lemons.com"
HTTP::uri "/fruit/TREE.html" } else { HTTP::header replace host "lemons.com" }
}
when HTTP_RESPONSE { HTTP::header replace [HTTP::host] lemons.com }
Any help would be greatly appreciated.
Your HTTP_RESPONSE is incorrect and unnecessary, it's trying to replace the HTTP header called lemons.com with lemons.com if a Host header existed in the response, or killing the TCP connection with a RST and causing a blank page if the Host header didn't exist in the response. Have a look in /var/log/ltm for TCL Errors to determine what's happening.
Case insensitive:
when HTTP_REQUEST { switch [string tolower [HTTP::uri]] { "/" - "/tree.html" { HTTP::uri "/fruit/TREE.html" } } HTTP::header replace Host "lemons.com" }
Case sensitive:
when HTTP_REQUEST { switch [HTTP::uri] { "/" - "/TREE.HTML" { HTTP::uri "/fruit/TREE.html" } } HTTP::header replace Host "lemons.com" }