Forum Discussion

JeffRay_129268's avatar
JeffRay_129268
Icon for Nimbostratus rankNimbostratus
Sep 07, 2015

Syntex Error

I am getting below error when updating Irule: My part of update is to redirect the string in uri health-blog to health-byte and remaining URI to be same as it is.

Error: line 25: [command is not valid in the current scope] [switch -glob [string tolower [HTTP::path]] { "/en/sitemap.xml" { set uri1 "/en-sitemap.xml" HTTP::uri "/en-sitemap.xml" log local0. "Find String= /en/sitemap.xml and Replaced uri: [HTTP::uri]" } "/ar/sitemap.xml" { set uri1 "/ar-sitemap.xml" HTTP::uri "/ar-sitemap.xml" log local0. "Find String= /ar/sitemap.xml and Replaced uri: [HTTP::uri]" } }] line 25: [command is not valid in the current scope] [string tolower [HTTP::path]] line 25: [command is not valid in the current scope] [HTTP::path] line 39: [command is not valid in the current scope] [}]

Irule is mentioned below:

when HTTP_REQUEST {

 tell server not to compress response
HTTP::header remove Accept-Encoding

 disable STREAM for request flow
STREAM::disable
 redirect autodiscover requests to autodiscover site

if { [string tolower [HTTP::path]] equals "/autodiscover/autodiscover.xml" } {

HTTP::respond 301 "Location" "https://autodiscover.domainnet.us/autodiscover/autodiscover.xml"

 redirect http://domainnet.us to https://www.domainnet.us along with any uri
              } elseif { [string tolower [HTTP::host]] equals "domainnet.us" } {
    HTTP::respond 301 "Location" "https://www.domainnet.us[string tolower [HTTP::uri]]"

} elseif { [string tolower [HTTP::uri]] starts_with "/health-blog/" } { set uri [string map {"/health-blog/" "/health-byte/"} [HTTP::uri]] HTTP::redirect "https://www.domainnet.us$uri" log local0. "outgoing URI = $uri" }

}

switch -glob [string tolower [HTTP::path]] {

    "/en/sitemap.xml*" {

set uri1 "/en-sitemap.xml" HTTP::uri "/en-sitemap.xml" log local0. "Find String= /en/sitemap.xml and Replaced uri: [HTTP::uri]" } "/ar/sitemap.xml*" { set uri1 "/ar-sitemap.xml" HTTP::uri "/ar-sitemap.xml" log local0. "Find String= /ar/sitemap.xml and Replaced uri: [HTTP::uri]" }\

        }

} when HTTP_RESPONSE {

 catch and replace redirect headers
if { [HTTP::header exists Location] } {
    HTTP::header replace Location [string map {"http://" "https://"} [string tolower [HTTP::header Location]]]

} 

 only look at text data
if { [HTTP::header Content-Type] contains "text" } {

     create a STREAM expression to replace any http:// with https:// for NET and preprod
    STREAM::expression {@http://s5.donet.us@https://s5.donet.us@ @http://s1.donet.us@https://s1.donet.us@ @http://s2.donet.us@https://s2.donet.us@ @http://s3.donet.us@https://s3.donet.us@ @http://s4.donet.us@https://s4.donet.us@ @preprod.donet.us@www.domainnet.us@ @http://www.domainnet.us@https://www.domainnet.us@}



     enable STREAM
    STREAM::enable
}

}

  • Looks like you're missing a closing curly bracket. Try this one:

    when HTTP_REQUEST {
    
         tell server not to compress response
        HTTP::header remove Accept-Encoding
    
         disable STREAM for request flow
        STREAM::disable
         redirect autodiscover requests to autodiscover site
        if { [string tolower [HTTP::path]] equals "/autodiscover/autodiscover.xml" } {
    
            HTTP::respond 301 "Location" "https://autodiscover.domainnet.us/autodiscover/autodiscover.xml"
             redirect http://domainnet.us to https://www.domainnet.us along with any uri
    
        } elseif { [string tolower [HTTP::host]] equals "domainnet.us" } {
                HTTP::respond 301 "Location" "https://www.domainnet.us[string tolower [HTTP::uri]]"
        } elseif { [string tolower [HTTP::uri]] starts_with "/health-blog/" } { 
            set uri [string map {"/health-blog/" "/health-byte/"} [HTTP::uri]]
            HTTP::redirect "https://www.domainnet.us$uri"
            log local0. "outgoing URI = $uri"
        }
    
    
        switch -glob [string tolower [HTTP::path]] {
            "/en/sitemap.xml*" { 
                     set uri1 "/en-sitemap.xml" 
                    HTTP::uri "/en-sitemap.xml" 
                    log local0. "Find String= /en/sitemap.xml and Replaced uri: [HTTP::uri]" 
            }
            "/ar/sitemap.xml*" { 
                 set uri1 "/ar-sitemap.xml"
                HTTP::uri "/ar-sitemap.xml"
                log local0. "Find String= /ar/sitemap.xml and Replaced uri: [HTTP::uri]"
            }
        }
    }   
    
    
    when HTTP_RESPONSE {
    
         catch and replace redirect headers
        if { [HTTP::header exists Location] } {
            HTTP::header replace Location [string map {"http://" "https://"} [string tolower [HTTP::header Location]]]
    
        } 
    
         only look at text data
        if { [HTTP::header Content-Type] contains "text" } {
    
             create a STREAM expression to replace any http:// with https:// for NET and preprod
            STREAM::expression {@http://s5.donet.us@https://s5.donet.us@ @http://s1.donet.us@https://s1.donet.us@ @http://s2.donet.us@https://s2.donet.us@ @http://s3.donet.us@https://s3.donet.us@ @http://s4.donet.us@https://s4.donet.us@ @preprod.donet.us@www.domainnet.us@ @http://www.domainnet.us@https://www.domainnet.us@}
    
    
    
             enable STREAM
            STREAM::enable
        }
    }