cancel
Showing results for 
Search instead for 
Did you mean: 

Replace path in redirect

RiverFish
Altostratus
Altostratus

Expectations:

using the old hostname (oldhostname.com) will redirect to the new hostname (newhostname.com)

using / (nothing after .com) will redirect to /newpath

using /oldpath/foo will redirect to /newpath/foo

 

The issue is the last part. If you do something like this...

 

when HTTP_REQUEST { if { [string tolower [HTTP::uri]] starts_with "/oldpath" } {     HTTP::redirect "/newpath[HTTP::uri]"     }  }

 

It grabs the oldpath, so it looks like this /newpath/oldpath. Please help if you can

1 ACCEPTED SOLUTION

Hello,

 

You can try to re-create your iRule by referring below article.

 

https://support.f5.com/csp/article/K48922683

View solution in original post

2 REPLIES 2

Hello,

 

You can try to re-create your iRule by referring below article.

 

https://support.f5.com/csp/article/K48922683

Mayur, we eventually found that article and were able to come up with the irule below which got us working. The switch statement is just some tweaks that are custom for our particular site. Thanks!

when HTTP_REQUEST { if { [HTTP::host] contains "oldhostname.com" } { set newhost "newhostname.com" set newpath [string map {"/oldpath/" "/newpath/"} [HTTP::uri]] HTTP::redirect "https://$newhost$newpath" return } else { switch [HTTP::uri] { "/" - "/oldpath" - "/oldpath/" - "/oldpath/login/" - "/newpath/login/" { HTTP::redirect "https://[HTTP::host]/newpath/login" } default {} } return } }