Forum Discussion
greenasp_41938
Nimbostratus
Aug 11, 2009Redirect url by subfolder
We currently have a domain that points to a set of servers (www.abc.com), however, we have a new requirement to have certain sub directories (not all) point to another set of servers. (i.e.- www.abc.com needs to point to the original set of servers and www.abc.com/content needs to be routed to our new set of servers. I am not sure how to create the irule to do this.
9 Replies
- That can be done in several ways. By a "set of servers", I assume you are referring to a "pool" in BIG-IP terminology. If this is the case, a simple iRule that inspects the URI can change the pool the connection is going to. Something like this:
when HTTP_REQUEST { switch -glob [string tolower [HTTP::uri]] { "/content*" { pool pool_1 } "/othercontent*" { pool pool_2 } default { pool pool_default } } }
This way any request to "/content*" will get routed to pool "pool_1", requests to "/othercontent*" will go to pool "pool_2" and everything else will go to pool "pool_default".
The switch "-glob" allows for wildcard substitutions so you can do exact matches or wildcard matches as I did with the asterisks.
Hope this helps...
-Joe - greenasp_41938
Nimbostratus
Sorry, but I am new to f5. What you provided is great. To be a little more specific this is what I am trying to do.
The website is www.abc.com. All traffic is currently directed to our current IIS servers. Tonight, we are deploying 2 drupal servers to handle some of the content. I only need to direct certain folders to the new drupal servers.
/content
/content/about-us
/content/my-home
/content/answers
/content/rssp
/content/privacy-policy
/content/terms-and-conditions
/content/faq
/content/contact-us
/content/state
/about-us
/answers
/logs
/state
/press
/admin
/users
/node
Everything under content is going to be redirected with the exception of /content/media. All other traffic needs to be passed on to our current iis servers. Is your sample code still the best way to handle this? - dennypayne
Employee
It looks like Joe's code is still the way to go, you just need to substitute the correct pool names and make an exception for /content/media.when HTTP_REQUEST { switch -glob [string tolower [HTTP::uri]] { "/content/media*" { pool original_pool } "/content*" { pool new_content } default { pool original_pool } } }
Denny - dennypayne
Employee
Unless you are saying that /about-us, /answers, etc all need to be sent to the new pool as well. Then those would need to be added to the switch in the same manner as I've done for /content* above.
Denny - greenasp_41938
Nimbostratus
yes, they need to be set to the new pool as well. - Colin_Walker_12Historic F5 AccountSo if you want /content/media to go to the original pool, your above list to all go to the new pool, and everything else to go to the original pool, then you want something like this:
when HTTP_REQUEST { switch -glob [string tolower [HTTP::uri]] { "/content/media*" { pool original_pool } "/about-us*" - "/answers*" - "/logs*" - "/state*" - "/press*" - "/admin*" - "/users*" - "/node*" - "/content*" { pool new_content } default { pool original_pool } } }
Which is exactly like the two examples above with your new examples added.
Colin - greenasp_41938
Nimbostratus
I can't seem to get it to redirect. To test I created a www.abc.com/test/test-page on the new drupal server. I then entered the following irule to test.
when HTTP_REQUEST { switch -glob [string tolower [HTTP::uri]] { "http://www.abc.com/test*" { pool content_pool } default { pool pool_abc.com } } }
We do have multiple domains running throught the f5. Currently running version BIG-IP 9.4.7 Build 320.1 Final - dennypayne
Employee
www.abc.com is not part of the URI. It is the hostname (HTTP::host), so [HTTP::uri] will never match "http://www.abc.com/test". The URI is just /test.
I would think you could safely ignore the domain names, unless you are trying to make some other decision based on it.
Denny - greenasp_41938
Nimbostratus
no, I tried it with the /test* first and it do not route it, so I thought that would help.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects
