Forum Discussion

dexter_22020's avatar
Icon for Nimbostratus rankNimbostratus
Jan 16, 2012

apache rewrite PT to iRules





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}$


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* data is fetched from tomcat (because it's part of the /* jkmount function) but the display on the browser address bar will remain instead of




Likewise, when users surf the display URL will be re-written to






Thanks in advance for any info.


5 Replies

  • Hi,

    I think this should be equivalent to the Apache rewrite rule:

    when HTTP_REQUEST {
         Check if the host is and the path does not already start with /web/foo
        if {[string tolower [HTTP::host]] eq ""}{
            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
         Check if the host is and the path does not already start with /web/foo
        if {[string tolower [HTTP::host]] eq ""}{
            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@@}


  • 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





  • Can you make a successful request from the LTM command line to tomcat using curl to get the content you're expecting?



    curl -v -H "Host:"



    For the response rewriting, does the server have compression or chunking enabled? Can you post an anonymized copy of the curl output?



  • Here's the snippet of the curl output. Note that is my tomcat server and I haven't enabled the irule you suggested when doing this curl test.








    curl -v -H ""


    * About to connect() to port 8181


    * Trying connected


    * Connected to ( 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: */*






    < 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 left intact


  • 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?