Forum Discussion

dp_119903's avatar
dp_119903
Icon for Cirrostratus rankCirrostratus
Sep 26, 2017

301 Redirect Using Data Group External File

This should be easy...and I see some posts on it, but I can't seem to get it to work.

We were given a list of hundreds of URL's that need 301 redirects. The host and URI in most cases is entirely different and unique so I can't just wildcard a redirect for everything to a single destination.

example:

https://oldsite.com/pdf/111 --> http://newsite.com/doc/222 https://oldsite.com/jpg/222 --> http://newsite.com/bmp/111

etc.

I have all of the old site to new site mappings and I read another post that said I should create an external data group as a string that has := as the separator, so I have a datagroup called "testuri" and it looks like this:

"; := ";

And I have an irule that says:


when HTTP_REQUEST {
      if {[set code_url [class match -value -- [string tolower [HTTP::host][HTTP::uri]] equals testuri]] ne ""}{
        HTTP::respond [getfield code_url " " 1] Location [getfield code_url " " 2]
      }
}

...but it doesn't work.

In the end all I need is an irule that looks for the inbound request and if it's in the data group then returns the new value that it should be mapped to.

This seems simple, but it's turning not to be as simple as I had hoped.

  • Hi Guy,

    Your
    class match
    command cannot hit any item in the data group. Because the item equals
    https://test.randomdomain.com/
    but your command searches
    [HTTP::host][HTTP::uri]
    in other word
    test.randomdomain.com/
    . Therefore, delete
    https://
    at the beginning of the item in the data group.