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.
5 Replies
- hoolio
Cirrostratus
Hi,
I think this should be equivalent to the Apache rewrite rule: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]" } } }
And here's a version which works with a stream profile to rewrite the response content and redirect Location header from /web/foo to nothing: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 } }
Aaron - dexter_22020
Nimbostratus
Thanks Aaron,
Almost there...
1. on your first suggestion, it doesn't seem to get the data from /web/foo on the tomcat server. All it get is the tomcat's default page not the contents from /web/foo
2. on the stream suggestion, same results as above, my stream profile has this:
source: /web/foo
target: - hoolio
Cirrostratus
Can you make a successful request from the LTM command line to tomcat using curl to get the content you're expecting?
curl -v http://1.1.1.1/web/foo/index.html -H "Host: test.domain.com"
For the response rewriting, does the server have compression or chunking enabled? Can you post an anonymized copy of the curl output?
Aaron - dexter_22020
Nimbostratus
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
- hoolio
Cirrostratus
It 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.
As far as the request URI rewriting, did that curl request return the content you were expecting? If so, can you compare the server logs for the request made via the VIP and iRule with the one direct to the server from the LTM command line?
Aaron
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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
