Forum Discussion

GerardoF83_3196's avatar
GerardoF83_3196
Icon for Nimbostratus rankNimbostratus
May 04, 2017

URL Redirect Parse

Hi Guys

 

I'm totally new at this, so I'm trying the following and I'm not sure if an iRule will do it

 

I need to redirect as below

 

http://abc.qwe.com/ghj/qwe/12345

 

to

 

http://mnb.lkj.com/asd/qaz/wsx/edc/12345

 

So it's a totally new URL and the only thing in common is last number. Also if user goes to host (http://abc.qwe.com or http://abc.qwe.com/ghj) it should be redirected to new host (http://mnb.lkj.com)

 

Can I get this done with an iRule or I need Data Group or maybe a policy?

 

Thanks in advance!

 

  • JG's avatar
    JG
    Icon for Cumulonimbus rankCumulonimbus

    Here's one [untested] :

    when HTTP_REQUEST {
        if { [string tolower [HTTP::host]] equals "abc.qwe.com" } {
            switch -glob -- [HTTP::path] {
                "/ghj/qwe/*"    {
                                    HTTP::redirect http://mnb.lkj.com/asd/qaz/wsx/edc/[getfield [HTTP::path] "/" 4]
                }
                "/"             -
                "/ghj/"         {
                                    HTTP::redirect http://mnb.lkj.com
                }
            }
        }
    }