Forum Discussion
Boris_Artemyev_
Nimbostratus
Aug 08, 2007Partial URI rewrite v 4.5
Hello,
I searched for a relative answer to no avail.
We would like to implement the following:
redirect http://www.mywebsite/my/very/long/dynamic/uri to http://www.mywebsite/our/very/long/dynamic/uri
"/dynamic/uri" part is challenging.
Any input will be highly appreciated.
Thank you,
Boris.
5 Replies
- hoolio
Cirrostratus
Hi,
If you always want to redirect requests that start with "/my/very/long", you could use something like this:rule my_rule { if (http_uri starts_with "/my/very/long/") { redirect to "https://www.foorbar.com/our/very/log/%u" } else { use pool http_pool } }
Else, if a string comparison won't work, you could use matches_regex to describe when to issue the redirect:rule my_rule { if (http_uri matches_regex "/my/very/long/(?:some_dynamic_string)") { redirect to "https://www.foorbar.com/our/very/log/%u" } else { use pool http_pool } }
[Edits: the %u is substituted for the original URI. And it's more resource intensive to use matches_regex versus one of the string comparisons like starts_with, contains or ends_with.]
Aaron - Boris_Artemyev_
Nimbostratus
Aaron,
Thanks a lot!
I thought %u contains the entire URI, will my redirect become
https://www.foorbar.com/our/very/long/my/very/long/teh_rest_of_the_dynamic_uri
In any event, I will try it out.
Boris. - hoolio
Cirrostratus
In the F5 lexicon, %h refers to the host and %u refers to the URI, so the example should work for you, assuming you're able to match just the requests you want redirected.
Thanks,
Aaron - Deb_Allen_18Historic F5 AccountI think Boris is right, that the URI will contain both the old part and the new part that way.
He'd need to use substr or some other text manipulation to re-build the URI, maybe something like this?rule my_rule { if (tolower(http_uri) starts_with "/my/very/long/") { redirect to https://www.foorbar.com/our/very/long/ + substr(http_uri, 14) } else { use pool http_pool } }
/deb - Deb_Allen_18Historic F5 Account(corrected syntax above)
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