Forum Discussion

Puli's avatar
Puli
Icon for Nimbostratus rankNimbostratus
Sep 11, 2012

Match and split a URI

How can i match and split a URI,

 

like below, eg :

 

http:/abc.com/about/communityprocess/maintenance/JMF2.0/$

 

re-direct to

 

abc.com/landingpage/$1

 

For example

 

http:/abc.com/about/communityprocess/maintenance/JMF2.0/hello.html re-direct to abc.com/landingpage/hello.html

 

it does'nt have to be just the filename, it could a url

 

http:/abc.com/about/communityprocess/$ re-direct to abc.com/landingpage/$1

 

How can match , extract the second part of incomming url and attached to the re-direct ?

 

thanks,

 

 

Puli.

 

  • You could use a switch statement for this. You can try something like this:

    
    when HTTP_REQUEST {
    log local0. "[IP::client_addr]:[TCP::client_port]: [HTTP::method] to [HTTP::host][HTTP::uri]"
    switch -glob [string tolower [HTTP::uri]] {
    "/about/communityprocess/maintenance/JMF2.0/hello.html" {
    log local0. "[IP::client_addr]:[TCP::client_port]: Redirecting to http://abc.com/landingpage/hello.html"
    HTTP::redirect "http://abc.com/landingpage/hello.html"
    }
    "/about/communityprocess/*" {
    log local0. "[IP::client_addr]:[TCP::client_port]: Redirecting to http://abc.com/landingpage/"
    HTTP::redirect "http://abc.com/landingpage/"
    
    If you need to take part of the original URI and include it in the redirect, you can use getfield to split it:
    HTTP::redirect "http://abc.com/landingpage/[getfield [HTTP::uri] "/about/communityprocess/" 2]"
    }
    }
    }
    

    Aaron