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
- hoolio
Cirrostratus
Hi Dave, - Dave_73612
Nimbostratus
Thanks for the reply, - 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"? - Dave_73612
Nimbostratus
Yes, it's always redirecting /something/index.htm to /something. - 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]]" } }
- Dave_73612
Nimbostratus
Right, - 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")}{
- Dave_73612
Nimbostratus
Edit - Ok after re-reading that addition, it wont be fit for purpose. - 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]]" } }
- Dave_73612
Nimbostratus
As long as that only redirects the last section to / that's ok.
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