aFlex to rewrite an IIS respose

Posted by TODDH

Hi aFlex Wizards.

I have a quick question. When using port translation (80 - 8080) standard port 80 on the frontend to a non-standard port on the backend. IIS responds with a redirect with the port# as part of the redirect which is past through to the client. this ends up as a dead link on the frontend. Is there a way to remove the port number from the host URI on the response?

Sample redirect.
<head><title>Document Moved</title></head>
<body><h1>Object Moved</h1>This document may be found <a HREF="MYLIFE.COM:8080/djp/">here</a></body<MYLIFE.COM:8080/djp/%22%3ehere%3c/a%3e%3c/body> >


Thanks,

-Todd-

Comments

  • edited July 2022
    Posted by ddesmidt

    Hi,

    When browsers receive a redirect, then look at the response header "Location".
    That's unusual to see servers sending a redirect with "Location" header + "http content".

    Anyway, here is the aFleX to remove the ":8080" in your server redirect response 
    Have a good day.
    Code:





    when HTTP_RESPONSE { # For all the redirects from the servers if { [HTTP::is_redirect] } { # Check if the location header contains ":8080" if {([HTTP::header "Location"] contains ":8080")} { # Remove ":8080" from the Location header regsub ":8080" [HTTP::header Location] "" new_location HTTP::header replace Location $new_location } } }





    Dimitri
  • edited February 2014
    Posted by ddesmidt

    In the example above, I was removing the ":8080" from the server redirect.
    You may have servers with ":8080" and others with ":8081" and ...
    Here is a generic aFleX that will remove any port from the redirect:

    Code:

    when HTTP_RESPONSE { # For all the redirects from the servers if { [HTTP::is_redirect] } { # Check if the location header contains a specific TCP port ":*" # Note: The location header can be with "http://" or "https://" # => Looking for ":" is not enough. I have to look for ":" followed by a number if {[string match {*:[0-9]*} [HTTP::header "Location"]] == 1} { # Remove ":*" from the Location header # Note: Look for ":" + any number up to the fist "/" regsub {:[0-9].*?/} [HTTP::header Location] "/" new_location HTTP::header replace Location $new_location } } }
Sign In or Register to comment.