Forum Discussion
apache rewrite PT to iRules
Hello,
Newbie on iRules here seeking help from you gurus.
I want to move this apache functionality to the Big-IP using iRules but I don't even know how to begin searching devcentral. I tried looking for it and the closest I think the equivalent is the STREAM profile. Tried it but of course it didn't work. Maybe I just don't understand STREAM profile.
This is the apache config:
RewriteEngine on
RewriteCond %{HTTP_HOST} test.domain.com$
RewriteRule ^/*(.+) /web/foo/$1 [PT]
tomcat backend
JkMount /* instance21
What this does:
1. My documentRoot is from the tomcat app servers serving /* - hence the jkmount /* function.
2. The rewrite lines /web/foo/$1 means that when someone goes to http://test.domain.com/web/foo/* data is fetched from tomcat (because it's part of the /* jkmount function) but the display on the browser address bar will remain http://test.domain.com/ instead of http://test.domain.com/web/foo/anyfile.html
Likewise, when users surf http://test.domain.com/web/foo/file.html the display URL will be re-written to http://test.domain.com/file.html
Thanks in advance for any info.
- hooleylistCirrostratusHi,
when HTTP_REQUEST { Check if the host is test.domain.com and the path does not already start with /web/foo if {[string tolower [HTTP::host]] eq "test.domain.com"}{ if { not ([HTTP::path] starts_with "/web/foo")}{ Prepend /web/foo to the path HTTP::path "/web/foo[HTTP::path]" } } }
when HTTP_REQUEST { Disable the stream filter by default STREAM::disable Check if the host is test.domain.com and the path does not already start with /web/foo if {[string tolower [HTTP::host]] eq "test.domain.com"}{ if { not ([HTTP::path] starts_with "/web/foo")}{ Prepend /web/foo to the path HTTP::path "/web/foo[HTTP::path]" } } } when HTTP_RESPONSE { Rewrite redirects if {[HTTP::is_redirect] && [URI::path [HTTP::header Location]] starts_with "/web/foo"}{ HTTP::header replace Location [string map {/web/foo ""} [HTTP::header Location]] } Set the stream expression for text responses if {[HTTP::header Content-Length] contains "text"}{ STREAM::expression {@/web/foo@@} STREAM::enable } }
- dexter_22020NimbostratusThanks Aaron,
- hooleylistCirrostratusCan you make a successful request from the LTM command line to tomcat using curl to get the content you're expecting?
- dexter_22020Nimbostratus
Here's the snippet of the curl output. Note that 1.1.1.1 is my tomcat server and I haven't enabled the irule you suggested when doing this curl test.
curl -v http://1.1.1.1:8181/web/foo/ -H "Host:test.domain.com"
* About to connect() to 1.1.1.1 port 8181
* Trying 1.1.1.1... connected
* Connected to 1.1.1.1 (1.1.1.1) port 8181
> GET /web/foo/ HTTP/1.1
> User-Agent: curl/7.15.5 (i686-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
> Accept: */*
> Host:test.domain.com
>
< HTTP/1.1 200 OK
< Server: Apache-Coyote/1.1
< Set-Cookie: JSESSIONID=4E2DBF9A596207D8C8B8DD6E6664E8BC; Path=/web/; HttpOnly
< Content-Type: text/html;charset=UTF-8
< Transfer-Encoding: chunked
< Date: Tue, 17 Jan 2012 20:27:50 GMT
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1207 0 1207 0 0 66714 0 --:--:-- --:--:-- --:--:-- 66714
100 18384 0 18384 0 0 887k 0 --:--:-- --:-
-:-- --:--:-- 8387k* Connection 0 to host 1.1.1.1 left intact
- hooleylistCirrostratusIt shouldn't be a problem rewriting chunked responses. If you had the server sending compressed responses you'd need to uncompressed them or reconfigure the server to not use compression. But that response isn't compressed.
Recent Discussions
Related Content
* 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