Forum Discussion

Fluidetom_12222's avatar
Dec 19, 2016

What's the best approach for an http:redirect with exceptions?

Hey guys,

We're going to move a SharePoint site and all its subsites to a new location in our SharePoint farm. I need to create new iRule to redirect all users to the new site except for one particular subiste. I have written the following iRule but I 'm not sure whether this is the most efficient way to proceed. Would you mind having a look and let me know if there's a better way to handle this?

TIA

Let's say I want ot redirect all requests for https://intranet.company.com/my_old_site to https://intranet.company.com/my_new_site except when it's a request for https://intranet.company.com/my_old_site/subsite_we_need_to_keep?

when HTTP_REQUEST { 

     Check if path starts with /my_old_site/
    if {
    [string tolower [HTTP::path]] starts_with "/my_old_site" &&
    [string tolower [HTTP::path]] not (starts_with "/my_old_site/subsite_we_need_to_keep")} then { 

          Modify HTTP::path to replace original request 
    HTTP::redirect [string map {/my_old_site /my_new_site} [HTTP::path]]
    }
 }

2 Replies

  • Looks good. May be use a variable:

    when HTTP_REQUEST { 
    set PATH [string tolower [HTTP::path]]
     Check if path starts with /my_old_site/
    if { $PATH starts_with "/my_old_site" && $PATH not (starts_with "/my_old_site/subsite_we_need_to_keep")}  { 
    
     Modify HTTP::path to replace original request 
    HTTP::redirect [string map {/my_old_site /my_new_site} [HTTP::path]] 
    }
    }
    
  • thanks for your reply. This is the final working version of my iRule

     when HTTP_REQUEST { 
        set PATH [string tolower [HTTP::path]]
    
         Check if path starts with /my_old_site/
        if {($PATH starts_with "/my_old_site") and not ($PATH starts_with "/my_old_site/subsite_we_need_to_keep")} then { 
    
             Modify HTTP::path to replace original request with new address 
            HTTP::redirect [string map {my_old_site /my_new_site} [HTTP::path]]
        }
     }