Forum Discussion

Stephen_Winter's avatar
Stephen_Winter
Icon for Nimbostratus rankNimbostratus
Jun 05, 2021

Having issue with String Map using variables/data group.

We are doing a migration of our local intranet set to the cloud and we want to redirect people to the new site in stages. The main problem is that the paths are changing slightly on some sites, som...
  • spalande's avatar
    Jun 05, 2021

    To use variable with string map, it expects list argument. Also no curly braces for defining variables. Try below code

    when HTTP_REQUEST {
    log local0. "Request URL: [HTTP::host][HTTP::uri]"
    if { [class match [HTTP::uri] starts_with intranet_redirect_datagroup] } {
    set full_uri [HTTP::uri]
    log local0. "full URI - $full_uri"
    set old_uri [class match -name [HTTP::uri] starts_with intranet_redirect_datagroup]
    set new_uri [class match -value [HTTP::uri] starts_with intranet_redirect_datagroup]
    log local0. "old_uri - $old_uri"
    log local0. "new_uri - $new_uri"
    set rewrite_uri [string map [list "$old_uri" "$new_uri"] [HTTP::uri]]
    log local0. "New full URI - $rewrite_uri" 
    HTTP::respond 302 Location "https://cloud1.sharepoint.com$rewrite_uri" "
    return
      }
    }