sub_filter and regexen?

Evan Miller emmiller at
Sun Dec 30 01:46:45 MSK 2007

Simon Mullis wrote:
> Hi All,
> Following on from my fun with proxy_pass yesterday...
> Problem:  Application with dedicated httpd server over which I have no
> control.  I want to present this to external web clients.
> Proxy pass now works great.  The relative hrefs in html created by the
> httpd application are no incorrect and need to be prepended with the
> appropriate path.
> I can't seem to find any detail in the docs regarding the sub_filter module.
> Does the sub_filter module accept regexes?  I specifically want to use
> capture groups for a search and replace.
> e.g. rewrite all hrefs in a page
> location /new/long/path {
>     rewrite ^/new/long/path/(.*) /$1 break;
>     proxy_pass
>     sub_filter  href='(.+)'> href='/new/long/path/$1'>;
>     sub_filter_once off;
> }
> Thanks in advance for any help with this.
> Kind Regards
> SM

(Just going through some old posts.) The sub_filter module does not 
accept regexes. But for the example above perhaps you could just:

     sub_filter "<a href='" "<a href='/new/long/path/";
     sub_filter_once off;

More information about the nginx mailing list