Forum Discussion
Steve_87971
Aug 15, 2012Nimbostratus
An efficient vanity URL redirect
Hi all,
I'm hoping you can give me some input on the efficiency of an iRule I've created. I've got 2x 3900 running 10.2.3.
Our devs have added a whole bunch (hundreds of thousands) of vanity URLs into our site map for the search engines to crawl. They then created a rule in ISAPI on each of the web servers to generate a 302 redirect to change the requested URI - a 302 was chosen as it preserves the address in the browser which is a requirement.
We have two problems with this - first, search engines don't really like the 302 and would prefer a 301, but this means changing the address in the browser and then the address wouldn't match the canononical name. Bad news bears.
Second, ISAPI creates processing on the servers which I'm sure would be handled better/faster and more appropriately on the F5. Oh and the ISAPI file is getting hideous with all the other stuff it does.
I've created the rule below which works but I don't know whether it could be more efficient:
when HTTP_REQUEST {
if {([HTTP::path] contains "/in/")}{
set var1 [URI::path [HTTP::uri] 1 1]
set var1 [concat [string trim $var1 "/"]]
set var2 [URI::basename [HTTP::uri]]
HTTP::uri /myapp.aspx?phrase=$var1&where=$var2
}}
With this rule in place, if you enter a value of www.mysite.com/steve/in/london, my servers would receive www.mysite.com/myapp.aspx?phrase=steve&where=london but your browser would keep the vanity URL. The trick is in seeing /in/ within the path and grabbing the words either side as var1 and var2, then re-writing the path that the server gets.
The rule works as is, but as it will need to front the VS on a very busy service I'd like to make sure it's as efficient as possible. Using a class is out as there are so many matching pairs, a switch might be better than an IF assuming it can use variables, but I can't see how to start with that.
Any help would be greatly appreciated.
Cheers, Steve
- Steve_87971NimbostratusOh yeah, I should probably add that this is dynamic - if the page you request doesn't exist the app will figure it out and offer an alternative.
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