Forum Discussion
Url redirection
Hi mj16othman ,
Try this :
when HTTP_REQUEST {
if { [string tolower "[HTTP::host][HTTP::path]"] contains "example.com/apps/test" }{
return
} else {
#HTTP::redirect "http://example.com"
HTTP::redirect "http://[HTTP::host]"
}
}
> you must assign the default pool to that virtual server.
use only one of those redirections :
HTTP::redirect "http://example.com"
HTTP::redirect "http://[HTTP::host]"
I hope this helps you
- whispererJun 08, 2023MVP
The iRule posted by should work, but you can clean it up a bit. Here we do the following:- More efficient string comparison using starts_with rather than contains. Also, more secure as a URL may be odd and repeat that string as part of URI path (unlikely though).
- Removed unnecessary comparison for host header. Likely there is no virtual hosting, so all (and only) example.com traffic hitting the virtual server. We only need it for return if path doesn't match our pattern.
- Support both https and http protocols. In case you perform or what to add SSL termination or what not.
- You could also get fancier and support multiple paths you want to check via data groups, or even use a variable for the comparison string portion
So here we have it.
when HTTP_REQUEST {
if { [string tolower [HTTP::path]] starts_with "/apps/test" }{
return
} else {
if { [TCP::local_port] == 443 }{
HTTP::redirect "https://[HTTP::host]"
} else {
HTTP::redirect "http://[HTTP::host]"
}
}
}- whispererJun 08, 2023MVP
Sorry for the formatting, but posting TCL code via the iPhone triggers an error on DevCentral!
"Correct the highlighted errors and try again.
Post flooding detected (community received posts of a unique message more than 1 times within 3,600 seconds)"
Thats even with just a simple "test" using the TCL </> option in the WYSIWYG editor. Strange.
- Leslie_HubertusJun 13, 2023Ret. Employee
Tagging LiefZimmerman so he can see your issue with sharing TCL code from your phone triggering a post flooding timeout.
- Jun 08, 2023
Hi whisperer ,
Thanks a lot ,
I have tested it in my internal Lab , it worked as expected for HTTP only however he can do the same for HTTPS but with offloading and redirecting to https at least.
mj16othman- whispererJun 08, 2023MVP
Mohamed_Ahmed_Kansoh Correct, for HTTPS you would need to have an appropriate VS with client SSL profile and listening on standard port 443. I always think about writing generic iRules so you can resume them for multiple applications.
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