cancel
Showing results for 
Search instead for 
Did you mean: 
Login & Join the DevCentral Connects Group to watch the Recorded LiveStream (May 12) on Basic iControl Security - show notes included.

Having issue with String Map using variables/data group.

Stephen_Winter
Nimbostratus
Nimbostratus

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, some are getting longer (adding sub directories), some are losing subdirectories...

 

So, I created a data group with the old<>new mapping and am trying to use the string map to replace one with the other in the URI string... But, it's not working.

 

Am I just missing something basic in "string map"? Does string-map not work if there are "/" in the strings? Any help would be greatly appreciated...

 

Thanks

 

-Stephen

 

iRule:

 

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"

 

  string map { $old_uri $new_uri } $full_uri

  log local0. "New full URI - $full_uri"

 

  log local0. "Redirect URL: cloud1.sharepoint.com$full_uri" 

HTTP::respond 302 Location "https://cloud1.sharepoint.com$full_uri" 

}

}

 

Data Group: intranet_redirect_datagroup

 

/sites/IT/K2DT/ := /sites/IT/newK2DT/

/sites/legal/ocw/ := /sites/ocw/

/sites/topdog/ := /sites/emt/td/

 

 

 

Logs... As you can see the "New full URI" is unchanged, even though it recognizes there is a match in the datagroup.

 

<HTTP_REQUEST>: Request URL: intranet/sites/IT/K2DT/SitePages/Home.aspx

<HTTP_REQUEST>: full URI - /sites/IT/K2DT/SitePages/Home.aspx

<HTTP_REQUEST>: old_uri - /sites/IT/K2DT/

<HTTP_REQUEST>: new_uri - /sites/IT/newK2DT/

<HTTP_REQUEST>: New full URI - /sites/IT/K2DT/SitePages/Home.aspx

<HTTP_REQUEST>: Redirect URL: cloud1.sharepoint.com/sites/IT/K2DT/SitePages/Home.aspx

 

 

1 ACCEPTED SOLUTION

SanjayP
MVP
MVP

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 } }

 

 

 

View solution in original post

3 REPLIES 3

SanjayP
MVP
MVP

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 } }

 

 

 

Stephen_Winter
Nimbostratus
Nimbostratus

This works perfectly! Thanks!

great to know. please mark this as answered