Forum Discussion

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

Does execution halt after http::respond?

I'm trying to set up a series of rules for an upcoming transition of our site to a WCM with wildly different URLs from our old site. What I want to know is if the code stops executing after an http::respond is issued or if I need to explicitly exit the code to prevent it from trying to match any further rules. Here's an example code block:

 

 

foreach item $::redirect_ids {

 

if {$item == $page_id} then {

 

HTTP::respond 301 Location "http://$::base_hostname/site/en/us/$item"

 

}

 

}

 

HTTP::respond 301 Location "http://$::base_hostname/site/us/en/home/Global/We-Have-Redesigned-the-Site.html?cid=ErrorPage$page_id"

 

 

So, I'll have a list of pageids that we want to send to these new pages, but if it doesn't match any of those explicitly redirected ids, just send it to a default error page. If page_id 12345 is in the list, it should do a 301 redirect to our base_hostname, plus the middle URI stuff, plus that same page id as a fake directory. But once it has done that, I don't want it to hit the next line of code that is the default behavior for no matches. Do I need an exit after the http::respond or is that implicit in the respond execution?

 

 

Thanks,

 

 

Dan O

3 Replies

  • If I understand you correct you want redirect if all http requests hit a know page_ID. If the page is part of your list you want redirect to an errorpage.

    Here is a snippet that may help

    
    foreach item $::redirect_ids {
    if { $item == $page_id } {HTTP::redirect "http://$::base_hostname/site/en/us/$item" }
    else {HTTP::redirect "http://$::base_hostname/site/us/en/home/Global/We-Have-Redesigned-the-Site.html?cid=ErrorPage$page_id" }
    }

    You don't need "then", because it's now implicit within irules, using IF statements. I also used redirect because that is essentially what you are doing with the "HTTP::Respond 301"

    Hope this helps

    /CB

  • Thanks for the suggestion. That likely wouldn't work properly, however, since the else clause would execute the first time the if clause failed to match, which would almost always be the first iteration of the loop. However, it would work if I just assign a variable in the loop and then redirect to the variable after the loop, so you did give me an idea. Here's what it would look like:

    
    set this_redirect "http://$::base_hostname/site/us/en/home/Global/We-Have-Redesigned-the-Site.html?cid=ErrorPage$page_id"
    foreach item $::redirect_ids {
         if { $item == $page_id } { set this_redirect "http://$::base_hostname/site/en/us/$item" }
    }
    HTTP::respond 301 Location $this_redirect

    So, you assign the default value prior to the loop and then if any iteration of the loop matches, it re-assigns the new value to the variable. The else clause isn't needed because once you get a match and the value is assigned, the rest of the list can iterate and nothing will happen.

    Additionally, isn't HTTP::redirect actually a 302(temporary), rather than a 301(permanent)? We need it to be permanent to ensure proper indexing by Google, etc.

    Thanks,

    Dan O