Forum Discussion

Jim_Betts_47293's avatar
Jim_Betts_47293
Icon for Nimbostratus rankNimbostratus
Mar 25, 2008

URL rewrite frustration

Howdy All:

 

 

After spending at least 4 hours searching DevCentral and dozens of attempts at trying to code the rules I need some help.

 

 

I have a web server (actually a Tumbleweed Secure Messenger) in my internal network (Inside FQDN=securemail.corp.com) that is accessed HTTP via port 8080. All access to this server is via URI "/securemail". I want users on the outside to access this system using HTTPS with our existing site certificate.

 

 

I have a large, elaborate iRule that I use to direct people to various pools depending on host names and URI that is working pretty well, what I want to do is to add some URI rewriting so that I can translate the inbound hostname to the inside domain hostname. I'm truncating SSL before I forward the requests but need to ensure that he responses are in SSL. Here is what I have so far:

 

 

when HTTP_RESPONSE {

 

if { $Target_URI starts_with "/messenger" } {

 

set host "www.mycomp.com"

 

HTTP::header replace Host "www.mycomp.com"

 

set location [HTTP::header value Location]

 

regsub {securemail\.corp\.com} $location "www.mycomp.com" newLocation

 

HTTP::header replace Location "$newLocation"

 

}

 

}

 

 

when HTTP_REQUEST {

 

if { $Target_URI starts_with "/messenger" } {

 

set host "securemail.corp.com:8080"

 

HTTP::header replace Host "securemail.corp.com"

 

set location [HTTP::header value Location]

 

pool Tumbleweed-SM

 

}

 

}

 

 

In summary here is what needs to happen:

 

 

Inbound request-> https://www.mycomp.com/messenger/xyz

 

Request forwarded-> http://securemail.corp.com:8080/messenger/xyz

 

Outbound response-> https://www.mycomp.com/messenger/xyz (with URI generated by server)

 

Response I'm getting-> http://securemail.mycomp.com/messenger/xyz

 

 

Any suggestions would be appreciated.

 

4 Replies

  • Hi there,

    Thats what I used to replace the HostHeader...

    Basically replacing the URI with the complete Request in a http class should be ok.

    Like replacing HTTP:uri with http://securemail.corp.com:8080[HTTP::uri]

    This will normally cause the hostheader to be ignored.

    Are you using a oneconnect profile ?

    when HTTP_REQUEST { 
    set my_host [string tolower [HTTP::host]] 
    if {[HTTP::host] starts_with "leon.demo.com"} {
    set destination_host hsrvepp1.demo.com
    set source_host http://leon.demo.com
    HTTP::header replace "Host" $destination_host}
    log local0. [HTTP::header Host]
    }
    when HTTP_RESPONSE { 
    set server_location [string tolower [HTTP::header Location]] 
    if {$server_location starts_with "http://hsrvepp1.demo.com"} {
    HTTP::header replace "Location" $source_host} 
    log local0. [HTTP::header Location]
    }

    Good Luck

    Wiesmann

  • Dear Weismann:

     

     

    The screen shot you attached pointed me in the right direction. The only further difficulty I encountered was that the system was doing redirects to "http://xxxx" rather than simply specifying the URI. I overcame this difficulty with this less than miraculous code:

     

     

    when HTTP_RESPONSE {

     

    if { [HTTP::status] contains "302" and $Target_URI starts_with "/messenger"} {

     

    set location [HTTP::header value Location]

     

    regsub {http:} $location "https:" newLocation

     

    HTTP::header replace Location "$newLocation"

     

    }

     

    }

     

     

    Again, thank you for your kind assistence.

     

     

    Jim
  • Hi Jim,

    You could make your rule slightly more efficient by using string map instead of a regex command and removing the intermediate variables:

    
    when HTTP_RESPONSE {
       if { [HTTP::status] == 302 and $Target_URI starts_with "/messenger"} {
          HTTP::header replace Location [string map {http:// https://} [HTTP::header value Location]]
       }
    }

    Aaron