Forum Discussion
Irules redirect/rewrite query
Hi all
I am new to the irules forum, and have been looking for the best way to handle a request come from our development team.
The request is as following, currently users browse to http://www.test.com/destination/xyz and would like to redirect users based on capturing the last bit of the url i.e xyz to http://www.test2.com/destination/xyz
So is it possible to capture the last part of a url with an irule and then pass this to a set url and append the capture part of the url, to add some more complication we then need to rewrite the url to the original for SEO purposes to maintain rankings.
Our f5’s are currently running 11.20. Build 2451.3, the servers hosting the sites are both in separate pools.
Thanks in advance
- Kevin_StewartEmployeeNot 100% clear on your requirements here, but guessing you need to redirect users from www.test.com to www.test2.com IF the end of the URL contains "/xyz"? If so:
when HTTP_REQUEST { if { ( [string tolower [HTTP::host]] equals "www.test.com" ) and ( [string tolower [HTTP::uri]] ends_with "/xyz" ) } { HTTP::redirect "http://www.test2.com[HTTP::uri]" } }
- Annsar_AkhtarNimbostratus
Hi Kevin
- Mohamed_LrhaziAltocumulusSearch the various iRule samples linked under the wiki entry for HTTP::uri
- Kevin_StewartEmployeeHow about something like this then:
when HTTP_REQUEST { if { [string tolower [HTTP::host]] equals "www.test.com" } { sample http://www.test.com/destination/xyz set firstpart [string range [HTTP::uri] 0 [expr [string last "/" [HTTP::uri]] -1]] set secpart [string range [HTTP::uri] [string last "/" [HTTP::uri]] end] log local0. "firstpart = $firstpart" log local0. "secpart = $secpart" HTTP::redirect "http://www.test2.com$firstpart$secpart" } }
- Annsar_AkhtarNimbostratusThanks, I will have a look at the wiki and have a play with the code sample. The page is used for SEO so any redirect away from the page would affect the rankings so would like to maintain the orignal URL to end users browser after redirecting them but not sure if this going to be possible.
- Kevin_StewartEmployeeFor the purposes of SEO, I'm guessing you'd need to maintain the original host value (www.test.com). Unless I'm still not understanding, how can you maintain SEO for www.test.com if you're physically redirecting users to www.test2.com? What's important - the host value or URI?
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