Forum Discussion

Joe_Pipitone's avatar
Joe_Pipitone
Icon for Nimbostratus rankNimbostratus
May 12, 2010

Redirects / rewrites conflicting

I have a master iRule which seems to be throwing a "Multiple redirect/respond invocations now allowed" The iRule is as follows. It tries to match certain urls typed in by the user, and redirects. Another part of the rule simply says if the uri begins with images, then rewrite to legacy.oursite.com/images. The 3rd part of the iRule strips the www from the domain. The errors I am getting are:

TCL error: redmond_redirects HTTP_REQUEST - 
Operation not supported. Multiple redirect/respond 
invocations not allowed line 1 invoked from within 
HTTP::redirect http://oursite.com[HTTP::uri] default arm line 1 
invoked from within switch -glob [HTTP::uri] { / { 
HTTP::redirect http://oursite.com } default { HTTP::redirect 
http://oursite.com... 

when HTTP_REQUEST { 
   if { [string tolower [HTTP::uri]] equals "/survey" or [string tolower [HTTP::uri]] equals "/survey/" } {
     HTTP::redirect "http://oursite.com/surveys/" 
   }
   if { [string tolower [HTTP::uri]] equals "/surveys" } {
     HTTP::redirect "http://oursite.com/newsurveys/" 
   }
   if { [string tolower [HTTP::uri]] equals "/anotherurl/survey2008" or [string tolower [HTTP::uri]] equals "/anotherurl/survey2008/" } {
     HTTP::redirect "http://oursite.com/whitepapers/2009/05/survey.aspx" 
   }
   if { [string tolower [HTTP::uri]] starts_with "/anotherurl/survey2007" or [string tolower [HTTP::uri]] equals "/anotherurl/survey2008/" } {
     HTTP::redirect "http://oursite.com/whitepapers/2009/05/2007survey.aspx" 
   }
   if { [string tolower [HTTP::uri]] equals "/subscribe" or [string tolower [HTTP::uri]] equals "/subscribe/" } {
     HTTP::redirect "https://some.domain.com/sub/MI?WP=PCODE" 
   }
   set my_uri [string tolower [HTTP::uri]]
  if { $my_uri starts_with "/images" } {
     redirect to oursite.com/images on matching URI
    HTTP::redirect http://legacy.oursite.com$my_uri
  }
      if { ([HTTP::host] eq "www.oursite.com") } { 
        switch -glob [HTTP::uri] { 
             "/" { HTTP::redirect "http://oursite.com" } 
             default {  HTTP::redirect "http://oursite.com[HTTP::uri]" }
        } 
    } 
}
Can anyone help me resolve these errors?

7 Replies

  • Hi Joe,

     

     

    I think you should add a return command just after every redirect in order to stop processing the rule right after it matches something.

     

     

    Something like this:

     

     

    HTTP::redirect "http://xxxxxx"

     

    return

     

     

    Regards,

     

    Jose Santiago Oyervides.

     

  • Well, the problem with that is - I always want the www to be stripped - so if it catches http://www.oursite.com/survey it will redirect to the correct URL, however it will leave the www in the url.

     

     

  • Hi Joe,

     

    After a redirect you must exit processing the next lines, in order to avoid multiple redirects, in your case if the uri is "/survey" matches the first and the second redirect.

     

     

    Regards.
  • Right - I understand completely. How can I also make sure that the www is taken out of the url? This needs to also happen.

     

     

    More than one case in this iRule will be true at the same time - if the user types in www.sitename.com/survey, they will need to be redirected to sitename.com/surveys - both redirecting and stripping the www.

     

     

    I've corrected this using a default statement, however it doesn't seem to want to work in Internet Explorer - it only works in Chrome and Firefox.
  • Can you try this:

    
    when HTTP_REQUEST { 
     
     if { ([HTTP::host] eq "www.oursite.com") } { 
                    HTTP::redirect "http://oursite.com[HTTP::uri]"
    return
            }
          switch -glob [string tolower [HTTP::uri]] { 
    "/survey" -
    "/survey/" {
    HTTP::redirect "http://oursite.com/surveys/"
    return
    }
    "/surveys" {
    HTTP::redirect "http://oursite.com/newsurveys/" 
    return
    }
    "/anotherurl/survey2008" - 
    "/anotherurl/survey2008/" {
    HTTP::redirect "http://oursite.com/whitepapers/2009/05/survey.aspx" 
    return
    }
    "/anotherurl/survey2007" {
    HTTP::redirect "http://oursite.com/whitepapers/2009/05/2007survey.aspx" 
    return
    }
    "/images*" {
    HTTP::redirect "http://legacy.oursite.com[HTTP::uri]"
    return
    }
    }
    }
     

    The script first redirects the user to the site without www if exists, if not, makes the redirects depending on the uri.

    Is this what you want? Are virtual servers the same for the domain with and without www?

    If you are trying to send to the web servers the requests without the www in the header, you can just replace the host header:

    HTTP::header replace Host oursite.com

    this way the user will never see a redirect, it would be transparent.

    please tell me if that helps you.

    regards.

    May be you are trying