Forum Discussion

chemaf_15095's avatar
chemaf_15095
Icon for Nimbostratus rankNimbostratus
Mar 22, 2010

iRule to imitate rewrite with proxy [P]

Hi,

 

I need help with iRules to do the same as a rewrite of Apache, but with the proxy option [P].

 

I do not want to rewrite the url, all links must remain with the public URL and not the internal.

 

I've seen some examples of iRules but can not get that work well:

 

http://devcentral.f5.com/Default.aspx?tabid=53&forumid=5&postid=813039&view=topic

 

http://devcentral.f5.com/Default.aspx?tabid=53&forumid=5&tpage=1&view=topic&postid=19947

 

 

Description of [L], [P] y [N] :

 

'proxy|P' (force proxy)

 

This flag forces the substitution part to be internally sent as a proxy request and immediately (rewrite processing stops here) put through the proxy module. You must make sure that the substitution string is a valid URI (typically starting with http://hostname) which can be handled by the Apache proxy module. If not, you will get an error from the proxy module. Use this flag to achieve a more powerful implementation of the ProxyPass directive, to map remote content into the namespace of the local server.

 

 

'last|L' (last rule)

 

Stop the rewriting process here and don't apply any more rewrite rules. This corresponds to the Perl last command or the break command in C. Use this flag to prevent the currently rewritten URL from being rewritten further by following rules. For example, use it to rewrite the root-path URL ('/') to a real one, e.g., '/e/www/'.

 

 

'next|N' (next round)

 

Re-run the rewriting process (starting again with the first rewriting rule). This time, the URL to match is no longer the original URL, but rather the URL returned by the last rewriting rule. This corresponds to the Perl next command or the continue command in C. Use this flag to restart the rewriting process - to immediately go to the top of the loop.

 

 

Also in case I need some parameters.

 

 

Here I put some examples:

 

1)

 

RewriteRule /aplication(.*) http://internal.server1.com/aplication/$1 [L,P]

 

 

2)

 

RewriteRule ^/myuri/(.*)\%2F(.*) /myuri/$1\%252F$2 [N]

 

RewriteRule ^/myuri(.*) http://internal.server2.com/myuri$1 [P]

 

 

Thanks,

 

  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    You can use the ProxyPass or ProxyPass for LTM v10 to rewrite the host and/or URI (as opposed to redirecting the client).

     

     

    http://devcentral.f5.com/wiki/default.aspx/iRules/proxypass

     

    http://devcentral.f5.com/wiki/default.aspx/iRules/proxypassv10

     

     

    It supports string and regex substitution. If you just want to rewrite the host and URI in requests, you could do this using a simpler iRule that calls HTTP::uri and HTTP::header replace Host $new_host in the HTTP_REQUEST event. You'd want to avoid using regexes if possible as string functions are more efficient.

     

     

    If you try either option and run into issues, can you post the iRule you're testing and log entries from /var/log/ltm showing the issue?

     

     

    Thanks,

     

    Aaron