Forum Discussion
Alex_3268
Nimbostratus
Jan 18, 2008Performaing complex Apache like rewrites
Hi,
I've been searching and reading this forum and others for information on replacing Apache rewrites with iRules but I'm still somewhat confused as to whether this is entirely possible and if it's even a good idea in the first place.
An example of the type of rewriting we do now is;
RewriteRule ^/([a-z])ws/wfs([a-z]+)_([0-9]+)/(wfs|wms)/(.*)$ \
http://hostname/wfs$2_$3/$4/$5There are a number of variations on the above. We do this to partially validate the parameters but mainly to provide a consistent uri format across a variety of applications.
From what I've read so far it appears doing this using iRules would be somewhat more complex and require pulling apart the uri, placing the components into variables, doing string matches and probably data group lookups, then putting it all back together?
Is there an easier way (ideally something very similar to Apache)?
Any help or advice would be greatly appreciated.
3 Replies
- hoolio
Cirrostratus
Hi,
Here would be an equivalent to the apache rewrite rule:Evaluate the regex against the HTTP host and URI. Save the 5 backreferences to match1 through match5 for later use regexp {^/([a-z])ws/wfs([a-z]+)_([0-9]+)/(wfs|wms)/(.*)$} [HTTP::host][HTTP::uri] m1 m2 m3 m4 m5 log local0. "New Host: hostname" HTTP::header replace Host "hostname" Escape the variable name using curly braces where necessary log local0. "New URI: /wfs${m2}_$m3/$m4/$m5" HTTP::uri /wfs${m2}_$m3/$m4/$m5
You can use the regexp command (Click here), to evaluate the regex and save the matches into backreferences. To set the HTTP host header, you can use 'HTTP::header replace Host $new_value'. To set the URI, you can use HTTP::uri $new_uri. If you wanted to send the client a redirect, instead of rewriting the host or URI, you could use 'HTTP::redirect $fully_qualified_url'.
You don't have an exact match to the syntax of Apache's mod_rewrite, but there is equivalent functionality using iRules.
Aaron - Alex_3268
Nimbostratus
Thanks Aaron, that looks like the thing I'm after. I'm wondering though, would I need to do anything for the HTTP_RESPONSE event?
Anyway, I'll have a play on Monday and see how I go.
Thanks again, it's much appreciated. - hoolio
Cirrostratus
Hi,
I believe the original rule is just rewriting the host and URI on requests. That's also what the rule example does. So you wouldn't need to rewrite response headers or data.
If you do what to modify response headers, you can use 'HTTP::header replace' (Click here). To replace content, you can use a stream profile and STREAM:: commands. Take a look at the STREAM::expression wiki page for an example (Click here)
Aaron
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