Forum Discussion

Stacy_Lanier_53's avatar
Stacy_Lanier_53
Icon for Nimbostratus rankNimbostratus
Jul 28, 2008

301 Redirect

I am trying to throw a URL redirect for a specific UserAgents in a file when a specific URL is entered by the user.

 

 

when HTTP_REQUEST {

 

if { ([matchclass [HTTP::header value User-Agent] equals $::user_agents]) and \

 

[HTTP::uri] equals "http://internalURL/www.craigslist.org"}

 

HTTP::respond 301 Location "http://www.craigslist.org[HTTP::uri]"

 

}

 

 

 

Can anyone see what I am doing wrong?

 

 

Thanks

 

6 Replies

  • Hi,

    You forgot a brace, You may need to be careful about uppercase and lower case.

    So for example it may be best to do:

      
      when HTTP_REQUEST {  
        if { ([matchclass [string tolower [[HTTP::header value User-Agent]] equals $::user_agents]) and ([string tolower[HTTP::uri]] equals "http://internalurl/www.craigslist.org")} {  
            HTTP::respond 301 Location "http://www.craigslist.org[HTTP::uri]"  
      }   
      

    You need then to have only lower case character in your user-agent class
  • I am getting the following error now if you might know what's wrong.

     

     

    line 1: [parse error: missing close-brace] [{

     

    line 2: [command is not valid in the current scope] [if { ([matchclass [string tolower [[HTTP::header value User-Agent]] equals $::user_agents]) and ([string tolower[HTTP::uri]] equals "http://internalurl/www.craigslist.org")} {
  • My Mistake it misses a closing brace

     

     

      
        when HTTP_REQUEST {    
          if { ([matchclass [string tolower [HTTP::header value User-Agent]] equals $::user_agents]) and ([string tolower[HTTP::uri]] equals "http://internalurl/www.craigslist.org")} {    
             log local0. "Match done"   
             HTTP::respond 301 Location "http://www.craigslist.org[HTTP::uri]"    
        }  
      }    
      

     

     

    Update: one bracket was incorrect in your code i missed it
  • I appreciate your help and got one more error

     

    line 2: [parse error: PARSE quoteExtra 199 {extra characters after close-quote}] [{ ([matchclass [string tolower [[HTTP::header value User-Agent]] equals $::user_agents]) and ([string tolower[HTTP::uri]] equals "http://internalurl/www.craigslist.org")}]
  • Hi,

    You should try the iRule editor it would save a lot of syntax issue.

    Here is one you should be able to copy/paste

     
     when HTTP_REQUEST { 
     if { ([matchclass [string tolower [HTTP::header "User-Agent"]] equals $::user_agents]) and ([string tolower [HTTP::uri]] equals "http://internalurl/www.craigslist.org")} { 
              log local0. "Match done" 
              HTTP::respond 301 Location "http://www.craigslist.org[HTTP::uri]" 
         } 
     }