Technical Forum
Ask questions. Discover Answers.
cancel
Showing results for 
Search instead for 
Did you mean: 

iRule assistance for subfolder redirect

captaincroc
Nimbostratus
Nimbostratus

Hi All,

 

iRule newbie here. I have a URL "https://blog.example.com/oldsubfolder/FBAR" that I would like redirected to "https://blog.example.com/newsubfolder/FBAR".

 

I tried using the below iRule but it doesn't preserve whats appended after the subfolder. Any assistance would be greatly appreciated.

 

when HTTP_REQUEST { 

if { !([HTTP::host] starts_with "https://blog.example.com/oldsubfolder/") } { 

HTTP::redirect "https://[HTTP::host]/newsubfolder/"

}

}

1 ACCEPTED SOLUTION

CA_Valli
MVP
MVP

Hello,

in this attempt I'm using the getfield command to split URI by "/oldsubfolder/" string, so that first "oldsubfolder" match would be field 1 and the rest of your URI will be field 2.

 

I'm replacing /oldsubfoler/ with new path manually and then appending the rest of your uri using field 2 syntax.

 

when HTTP_REQUEST {
 if { [HTTP::uri] contains "/oldsubfolder/"} {
   HTTP::redirect https://[HTTP::host]/newsubfolder/[getfield [HTTP::path] "/oldsubfolder/" 2]
 } 
}  

I haven't had the chance to test this in a lab, please do before installing.

 

View solution in original post

1 REPLY 1

CA_Valli
MVP
MVP

Hello,

in this attempt I'm using the getfield command to split URI by "/oldsubfolder/" string, so that first "oldsubfolder" match would be field 1 and the rest of your URI will be field 2.

 

I'm replacing /oldsubfoler/ with new path manually and then appending the rest of your uri using field 2 syntax.

 

when HTTP_REQUEST {
 if { [HTTP::uri] contains "/oldsubfolder/"} {
   HTTP::redirect https://[HTTP::host]/newsubfolder/[getfield [HTTP::path] "/oldsubfolder/" 2]
 } 
}  

I haven't had the chance to test this in a lab, please do before installing.