Forum Discussion
Redirect irule from second field
Hi Thicardoso21 ,
As Enes_Afsin_Al sent it will be sufficient for your request exactly.
> May I have understood your request in a different way , please correct for me , I think you need to change the old " Host name " FQDN each time regardless /content1/ exists on request or not.
so I have created and irule matchs your request , also it prevents the old Host name and refirect to the new hostname each time anyone put the old url.
So I wrote this iRule :
when HTTP_REQUEST {
if {(([string tolower [HTTP::host]] equals "mysite.com") ||([string tolower [HTTP::host]] equals "newsite.com")) and ([string tolower [HTTP::path]] starts_with "/content1")}{
HTTP::redirect https://newshopping.asm.f5/[string map {"/content1" "/"} [HTTP::path]]
} else {
if {(([string tolower [HTTP::host]] equals "mysite.com") and ([string tolower [HTTP::path]] starts_with "/"))}{
HTTP::redirect "https://newsite.com[HTTP::path]"
}
}
}
> I added this Part : ||([string tolower [HTTP::host]] equals "newshopping.asm.f5")
to eliminate any possibility to see " Content1 " with old or new hostname , I though that if you are redirected to the new web site " newsite.com" , and want to retrieve /Content1/anythingelse or Click on a button on new web page retieves directly /content1/anythingelse Resource , so it will appeare " newsite.com/content1/anythingelse" , So I have put this condition to eliminate the existance of /content1/ resource with old hostname and new as well.
> After " else " Statement , it is to redirect all requests to old host name to new host name regardless what are the rest of uri path.
you can remove it if you want to redirect old hostname to new hostname with only existance of /Content1/ resource path in Requests .
Regards
Answering your question, we would change the old hostname from mysite.com to newsite.com, only if /content1 is present. If not, redirect is not required.
Thanks for adding those extra parts and explain your code. It looks great!
I will also setup this one in our lab and test it next week. I keep you posted.
Many thanks..
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com