Forum Discussion
URL redirect with Data Group
I am trying to use data groups to redirect URL, however the data group value is just appending to the end of the original URL in the web browser. Same result in Chrome, IE, and Firefox. I am not sure what I am doing wrong.
iRule: when HTTP_REQUEST { if { [class match -name [HTTP::host][HTTP::uri] equals datagroup_redirects] ne ""} { HTTP::redirect [class match -value [HTTP::host][HTTP::uri] equals datagroup_redirects] } }
Data Group: "www.test1.com/stuff/" := "www.site1.com/morestuff/", "www.test2.com/stuff/" := "www.site2.com/morestuff/", "www.test3.com/stuff/" := "www.site3.com/morestuff/", "www.test4.com/stuff/" := "www.site4.com/morestuff/", "www.test5.com/stuff/" := "www.site5.com/morestuff/", "www.test6.com/stuff/" := "www.site6.com/morestuff/"
When I put www.test1.com/stuff/ in the web browser I just end up with www.test1.com/stuff/www.site1.com/morestuff/ instead of just www.site1.com/morestuff/
Any ideas where I went wrong?
1 Reply
Hi Amass87,
take a look to the iRule below. It uses a slightly optimized syntax (just a single [class] execution) and also point out the reason why you're not getting redirected to external sites...
when HTTP_REQUEST { if { [set redirect [class match -value "[HTTP::host][HTTP::uri]" equals datagroup_redirects]] ne ""} then { HTTP::redirect "$redirect" ; Redirect to a sub-path/file within the current path HTTP::redirect "/$redirect" ; Redirect to a sub-path/file relational to / (www-toot) HTTP::redirect "//$redirect" ; Absolute Redirect protcol independent HTTP::redirect "http://$redirect" ; Ablsolte Redirect to HTTP HTTP::redirect "https://$redirect" ; Absolute Redirect to HTTPS } }Note: I would recommend to add the location prefixes directly into your datagroup. On this way you could specify them per entry as needed.
Cheers, Kai
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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