0

I am beginning to use lua especially with nginx. I need to rewrite the URLs within the html page i.e. let's say <a href="http://toberewritten.com">link1</a> should be rewritten to <a href="http://rewritten.com">link1</a>

The lua html parser at https://github.com/wscherphof/lua-htmlparser provides the URL but as far as I understand from its documentation, it will not rewrite the URL. I can perhaps reconstruct the page but was wondering if there is already a tool that would do that

Thanks for any inputs

doon
  • 2,311
  • 7
  • 31
  • 52

2 Answers2

4

You could try the official http://nginx.org/r/sub_filter, which is part of an official module that's already part of nginx (although it's not built by default, so, you'd have to recompile anyways).

sub_filter  http://toberewritten.com    http://rewritten.com;
sub_filter_once off;
cnst
  • 25,870
  • 6
  • 90
  • 122
2

You may try https://github.com/agentzh/replace-filter-nginx-module

location / {
    # caseless global substitution:
    replace_filter 'toberewritten' 'rewritten' 'ig';
    replace_filter_types text/plain text/css;
}
Michael
  • 1,322
  • 11
  • 17