Forum Discussion
Dave_73612
Nimbostratus
Jul 01, 2009Multiple 301 redirects and F5 performance
Hi guys,
I have a requirement to do over 40 301 redirects (google ranking purposes) for one of our websites which I was going to implement via IRule attached to the Virtual server for the site.
The IRule is structured as follow's:
when HTTP_REQUEST {
if { [HTTP::uri] equals "/index.html" } {
HTTP::respond 301 Location "blah"
}
if { [HTTP::uri] equals "/index.html" } {
HTTP::respond 301 Location "blah"
}
if
etc covering the 40 redirects.
I am wondering if there is a "faster" way to write this code?
Would url rewrites be of any benefit?
What is the performance overhead of running this Irule?
Is this the right approach?
Thanks in advance,
Dave
11 Replies
- hoolio
Cirrostratus
Hi Dave,
A switch statement would probably be easier to manage and be more efficient. Can you provide a few more examples of the mappings between requesteed URI and the redirect locations?
Thanks,
Aaron - Dave_73612
Nimbostratus
Thanks for the reply,
Mappings are based on the explicit URI string and are usually redirecting, for example: www.blah.co.uk\blah\index.htm to www.blah.co.uk\blah.
Another example would be www.blah.co.uk\blah\blah\index.htm to www.blah.co.uk\blah\blah and so on for 40 different uri's.
Cheers,
Dave - hoolio
Cirrostratus
Is there any pattern to the rewriting? Can you say that you always want to redirect //index.htm to /? Or is it something you need to explicitly map out as 'if URI is "this" redirect to "that"?
Aaron - Dave_73612
Nimbostratus
Yes, it's always redirecting /something/index.htm to /something.
Mind you it could be /something/something/something/something/index.htm to /something/something/something/something/.
Regards,
Dave - hoolio
Cirrostratus
I assume the application won't redirect the client back to /something/index.htm. How about this then:when HTTP_REQUEST { Check if request ends with /index.htm if {[HTTP::path] ends_with "/index.htm"}{ HTTP::respond 301 Location "[string map {/index.htm ""} [HTTP::uri]]" log local0. "Redirecting to [string map {/index.htm ""} [HTTP::uri]]" } }
Note that RFC2616 states the Location header value must be a fully qualified domain name, but browsers accept a local URI. You may want to hardcode the protocol and domain in the iRule.
Aaron - Dave_73612
Nimbostratus
Right,
If that works that would be fantastic.
I will give it a test in staging today - Thanks for the help.
D - hoolio
Cirrostratus
If your site has an index.htm file in the root (/index.htm) you would probably not want to redirect clients who request it to a null URI. So you might want to add a check for a path not equal to /index.htm before rewriting it:if {[HTTP::path] ends_with "/index.htm" and not ([HTTP::path] eq "/index.htm")}{
Aaron - Dave_73612
Nimbostratus
Edit - Ok after re-reading that addition, it wont be fit for purpose.
One of the required redirects is for example www.blah.com/index.htm to www.blah.com.
The default page of all folders is index.htm - we are doing this so as not to dilute google rankings.
D - hoolio
Cirrostratus
So you do want to redirect a request for /index.htm to / ? If so, you could just check for /index.htm and replace it with / in the redirect:when HTTP_REQUEST { Check if request ends with /index.htm if {[HTTP::path] ends_with "/index.htm"}{ HTTP::respond 301 Location "[string map {/index.htm /} [HTTP::uri]]" log local0. "Redirecting to [string map {/index.htm /} [HTTP::uri]]" } }
Aaron - Dave_73612
Nimbostratus
As long as that only redirects the last section to / that's ok.
For example:
www.blah.com/blah/blah/index.htm needs to be redirected to www.blah.com/blah/blah/ not to www.blah.com/
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
