Forum Discussion

Mr__T's avatar
Icon for Cirrus rankCirrus
Feb 23, 2023

Irule Vs rewrite - FQDN hostname

Hi All,

New to IRules, and rewrites. 

Clients will type, I need to redirect to another URL (working via IRule) that the server understands but keep the friendly name in the browser post every response. Protocol is https already E3E. T

Your help is appreciated.


if { [HTTP::host] equals ""} {
if { [HTTP::path] equals "/" } {
HTTP::redirect " /something/etc/etc/etc.html"

19 Replies

  • Mr__T So a few things stand out to me. First is that you don't want a redirect you would like a rewrite but in your rewrite it looks like you want to add on a port at the end of the host which shouldn't be necessary because your pool member should be listening on that port already. The last is whenever they hit just "/" as the URI do you want to redirect them to a specific path? So as an example of how I believe this works.

    User requests
    F5 responds with a redirect to
    User now requests
    F5 rewrites to
    F5 sends request to server on
    Response comes back from server and F5 rewrites to
    F5 sends response back to client for

    If for some reason I did not understand this correctly can you provide additional information as to how it has to function?

    • Mr__T's avatar
      Icon for Cirrus rankCirrus

      Hi Paulius,

      The long URL is what the app has hardcoded and will only respond to that URL. So my goal was to make sure the client only sees the frienly name after the redirects happen. I tried rewrite policies but the IRule seems to be the way to go. The redirect to he long URL works fine, but they dont want to see the servername rather FQDN. 

      Does this make sense?

      • Mr__T If your pools have multiple pool members I do not believe this will be possible because you will require mapping a single FQDN to multiple server names depending on the pool member that you are sent to. Your best bet here would be to work with the server/app admins to see if they have a way of changing what they expect for the host and path. Typically all of this can be done at the server level instead of performing a bandaid at the F5 which in some cases such as yours will not work because of the single FQDN to many names issue.

  • HTTP::redirect will effectively redirect the client to the new location, and will change the url in the browser. What you need is to replace the host header in the pool side of the connection as described here

    when HTTP_REQUEST {
       # Check if requested host doesn't start with
       if {not ([string tolower [HTTP::host]] starts_with "")}{
          # Replace the host header value with
          HTTP::header replace Host ""

    And to replace the path with another path without redirection, this is described here :

    when HTTP_REQUEST {
        if { [HTTP::uri] starts_with "/sometext" } {
            set uri [string map -nocase {"/sometext" "/newtext"} [HTTP::uri]]
            HTTP::uri $uri


      • Sorry for the ambiguous reply. No you can do it with one iRule and one when HTTP_REQUEST block containing all the replacement logic you need. 

        Two iRules can work too but there is no need to go this way in your case.