Forum Discussion

Bob_10976's avatar
Bob_10976
Icon for Nimbostratus rankNimbostratus
Sep 08, 2010

Append to or Rewrite URI

Hello all...

We have launched ADFS in our network and we'd like to setup an iRule so that when a user goes to the website, mydomain.com, that an iRule either appends or rewrites the URI so that the it includes the realm for these users.It should look something like this: https://mydomain.com/Pages/SiteSpla...tion:Realm. The trick is that "?whr=urn:federation:Realm" needs to append to any and all URLs, so in case someone sends another person a link via email to go to the link https://mydomain.com/bob/home.aspx that the "?whr=urn:federation:Realm" is appended to that as well. Also since its' possible that some URLs will contain a "?" already then we have to account for that because, from my understanding, you can't have two "?" in the URI.

Also I was wondering is it possible that the "?whr=urn:federation:Realm" be added but not show up in the Browser, keeping the user's URL window clean of this appeand or rewrite?

Working with one of my dev folks we came up with this, which doesn't seem to work but I'm not sure where our issue is. If anyone has any suggestion or thoughts please let me know.

 
when HTTP_REQUEST { 
switch "[string tolower [HTTP::host]]" { 
"mydomain.com" {
 if {not [string tolower [HTTP::uri]] contains "whr=urn:federation:Realm"}{
 if {[string tolower [HTTP::uri]] contains "?"}{
 HTTP::uri [append [HTTP::uri] "&whr=urn:federation:Realm"]
 } 
{
 HTTP::uri [append [HTTP::uri] "?whr=urn:federation:Realm"] 
} } } } }

Thanks in advance..

Bob

2 Replies

  • Hi Bob,

    A few tips:

    - You can use parenthesis to perform a negation on this line. You can also check just the query string instead of the full URI using HTTP::query. And if you're setting one string to lower case you should set the string you're checking for to lower case as well.

    Original:

    
              if {not [string tolower [HTTP::uri]] contains "whr=urn:federation:Realm"}{
    

    Updated:

    
              if {not ([string tolower [HTTP::query]] contains "whr=urn:federation:realm")}{
    

    To append something to the URI, you can use:

    HTTP::uri "[HTTP::uri]?whr=urn:federation:Realm"

    Aaron
  • Aaron...

     

     

    Thanks for the feedback. My dev ended up coming up with the below code. It seems to work and figured I'd post it in case anyone can benifit from it. I'm not a coder by any means so if theres a better way to do what we did, feel free to comment.

     

     

    
    when HTTP_REQUEST {
             switch "[string tolower [HTTP::host]]" { 
         "domainname.com" {
             set lowerUri [string tolower [HTTP::uri]] 
             if {$lowerUri contains "whr=urn:federation:Realm"}{ 
                   set hasWHR 1    
                } 
                {
                    set hasWHR 0
                 }
              if {!$hasWHR} 
                 {
                    set newURI [HTTP::uri]  
                    if {[string tolower [HTTP::uri]] contains "?"}
                 {
                             append newURI "&whr=urn:federation:Realm"
                 }
                 {
                             append newURI "?whr=urn:federation:Realm"
                 }
                 HTTP::uri $newURI
              }
          }
        }
      }