Rewrite Public Host Name to Internal Host Name

Hello,

Trying to modify the public URL to the local URL for IIS backend servers, along with using host header redirection.

So trying to -

draven.com rewrite to draven.local - then switch HTTP:host pool IIS_Server_Draven_pool and ninja.com rewrite to ninja.local - then switch HTTP:host pool IIS_Server_Ninja_pool

What I have so far with the host header redirection -

when HTTP_REQUEST { switch [HTTP::host] { ninja.com { pool IIS_Server_Pool_Ninja } draven.com { pool IIS_Server_Pool_draven } default { reject } } }

Im having trouble working out how to preform the rewrite then switch the host header to the correct pool. I have made the public URL working going direct to the backend server through the host header redirection.

Additional would like to try to have the “.com” being rewrote to “.local” en mass rather then code per site. Thanks in advance.

Hi, you need to change only the host header request? Try something like this:

when HTTP_REQUEST {
    set host [string map {".com" ".local"} [HTTP::host]]
    HTTP::host $host

    switch $host { 
        ninja.local { pool IIS_Server_Pool_Ninja } 
        draven.local { pool IIS_Server_Pool_draven } 
        default { reject } 
    }
}

When using -

when HTTP_REQUEST { set host [string map {“.com” “.local”} [HTTP::host]] HTTP::host $host

switch host { 
    ninja.local { pool IIS_Server_Pool_Ninja } 
    draven.local { pool IIS_Server_Pool_draven } 
    default { reject } 
}

}

Updating the iRule returns an error - [wrong args] [HTTP::host $host]

Addtionally when using -

when HTTP_REQUEST { HTTP::host [string map {“.com” “.local”} [HTTP::host]]

switch HTTP:host { 
    ninja.local { pool IIS_Server_Pool_Ninja } 
    draven.local { pool IIS_Server_Pool_draven } 
    default { reject } 
}

}

Updating the iRule - line 2: [wrong args] [HTTP::host [string map {“.com” “.local”} [HTTP::host]]]

Any advice on what im doing wrong?

Solution Found -

WHEN HTTP_REQUEST { set header [string map {“.com” “.local”} [HTTP::header “Host”]] HTTP::header replace host $header switch $header { ninja.local { pool IIS_Server_Pool_Ninja } draven.local { pool IIS_Server_Pool_draven } default { reject } } }

Thanks For your help

I think you missed here: “switch **host** {” have to be like this: “switch **$host** {”. But, taking the hint of Parker, do not use variable, do the following: when HTTP_REQUEST { HTTP::host [string map {“.com” “.local”} [HTTP::host]] switch [HTTP::host] { ninja.local { pool IIS_Server_Pool_Ninja } draven.local { pool IIS_Server_Pool_draven } default { reject } } }