Forum Discussion

Thiyagu_343098's avatar
Thiyagu_343098
Icon for Nimbostratus rankNimbostratus
Jul 04, 2018

irule help to fix the error

Hello all,

 

I'm getting below error while executing this script.

when HTTP_REQUEST { if {[string tolower [HTTP::host]] contains "test1.com"}{ set newurl [string map -nocase {"test1.com" ""} [[HTTP::host] "test2.com" 1]] HTTP::respond 301 Location "https://[HTTP::host $newurl][HTTP::uri]" } }

 

error log: TCL error: /Staging_CC/IRULE_URL_REDIRECT_TEST_2 - invalid command name "net.staging.test1.com" while executing "[HTTP::host] "test2.com" 1"

 

Thanks a lot in advance for any of your help to fix the issue.

 

Regards, Thiyagu

 

2 Replies

  • Can you describe what you're trying to do, it looks like you're attempting to replace the host header but your formatting and syntax is muddled.

    If just replacing host header you can try something like this

    when HTTP_REQUEST { 
        if {[string tolower [HTTP::host]] contains "test1.com"} { 
            set newHost "test2.com"
            HTTP::header replace Host $newHost 
        } 
    }
    
  • This code will redirect :

     

    • to
    • net.staging.test1.com to net.staging.test2.com
    when CLIENT_ACCEPTED {
        set redirect_list [list ".test1.com" ".test2.com"]
    }
    when HTTP_REQUEST {
        log loca0. "Request from host: [HTTP::host]"
        if {[string tolower [HTTP::host]] ends_with [lindex $redirect_list 0]} {
            set newHost [string map $redirect_list [HTTP::host]]
            log local0. "Host contains test1.com, redirecting to https://$newHost[HTTP::uri]"
            HTTP::respond 301 Location https://$newHost[HTTP::uri]
        } else {
            log local0. "Host: [HTTP::host] does not match the condition"
        }
    }