URL Change

I have an open source application, similar to Sharepoint, that build URL’s on the fly. I have an SSL cert on the F5 to make it https://, but the server is clear, http://. For some reason, one of the links the application builds inserts the http:// URL inside the https:// URL. Here is an example:

I want this:

http://mysite.com/some/dir

I get this

http://mysite.comhttp//mysite.com/some/dir

Is there a way to strip out a string within a URL?

Would I need a redirect rule that that sends to the correct host, while preserving the original URI? What would this look like?

Thanks

Jeff

Hi Jeff,

I’d try to fix the app first. If that’s not an option, you can rewrite the response headers and/or content with an iRule. To rewrite the header (typically the Location header in a redirect) you can use the following rule:

when HTTP_RESPONSE {  
    
      Check if response is a redirect  
     if {[HTTP::is_redirect]}{  
    
         Replace http//mysite.com with nothing if it's present in the Location header value  
        HTTP::header replace Location [string map {http//mysite.com ""} [HTTP::header value Location]]   
     }  
  }

If you need to perform the replacement in the response content, you can add the stock stream profile and then use an iRule to configure the search/replace strings:

when HTTP_RESPONSE {  
    
      Check if response is a redirect  
     if {[HTTP::is_redirect]}{  
    
         Replace http//mysite.com with nothing if it's present in the Location header value  
        HTTP::header replace Location [string map [list http//mysite.com ""] [HTTP::header value Location]]   
     }  
      Check if response content type is text  
     if {[HTTP::header value "Content-Type"] starts_with "text"}{  
    
         Set the stream expression  
        STREAM::expression "@http//mysite.com@@"  
    
         Enable the stream filter  
        STREAM::enable  
     } else {  
         Response wasn't text, so disable the stream filter  
        STREAM::disable  
     }  
  }

If it’s a typo that http//mysite.com is missing the :, you can use http://mysite.comhttp://mysite.com as the search string and replace it with http://mysite.com. You’d then want to use the following string map and STREAM::expression replacement strings:

Old:

HTTP::header replace Location [string map [list http//mysite.com “”] [HTTP::header value Location]]

New:

HTTP::header replace Location [string map [list http://mysite.comhttp://mysite.com http://mysite.com] [HTTP::header value Location]]

And, for the STREAM::expression:

Old:

STREAM::expression “@http//mysite.com@@”

New:

STREAM::expression “@http://mysite.comhttp://mysite.com@http://mysite.com@”

You can check the STREAM::expression wiki page (Click here ) for details on configuring a stream and HTTP profile for this rule.

Aaron

Thanks for the reply…

I tried your suggestions, but they did not work. I think because it is not really a HTTP header that I need to change. If I look at the whole stream, I see that it is the actual GET request that I need to change:

(Request-Line) GET //mysite.com/some/dir/ HTTP/1.1

Is there a way to search for a string within a GET request and delete it?

Thanks

Jeff

Thanks for the reply…

I tried your suggestions, but they did not work. I think because it is not really a HTTP header that I need to change. If I look at the whole stream, I see that it is the actual GET request that I need to change:

(Request-Line) GET //mysite.com/some/dir/ HTTP/1.1

Is there a way to search for a string within a GET request and delete it?

Thanks

Jeff

Hi Jeff,

Can you use a browser plugin like Fiddler for IE or HttpFox for FF to see what the server is actually sending back in response headers and/or the body?

You can rewrite the URI, but it might be cleaner to figure out why the response rewriting isn’t working. The find/replace strings might be wrong. Or the server might be compressing the response content. LTM doesn’t decompress the response content when applying the stream filter so it wouldn’t be rewritten.

If you do want to rewrite the URI, you can use the same string map command with HTTP::uri:

when HTTP_REQUEST { 
  
     Check if URI starts with //mysite.com 
    if {[HTTP::path] starts_with "//mysite.com" 
  
        Replace //mysite.com with / in the path 
       HTTP::path [string map {//mysite.com /} [HTTP::path]]  
    } 
 }

Aaron