有没有任何工具或实用程序可以重写HTML页面中的URL?

我开始使用 lua,特别是与 nginx 搭配使用。我需要重写 html 页面内的 URL,例如 <a href="http://toberewritten.com">link1</a> 应该被重写为 <a href="http://rewritten.com">link1</a>

lua html 解析器在 https://github.com/wscherphof/lua-htmlparser 提供了 URL,但据我理解从文档上看,它将不重写 URL。我可以重构页面,但想知道是否已经有工具可以完成这个任务。

感谢您提供的任何意见。

点赞
用户577792
用户577792

你可以尝试使用https://github.com/agentzh/replace-filter-nginx-module

location / {
    # 不区分大小写的全局替换:
    replace_filter 'toberewritten' 'rewritten' 'ig';
    replace_filter_types text/plain text/css;
}
2014-01-08 11:30:09
用户1122270
用户1122270

你可以尝试官方的http://nginx.org/r/sub_filter, 这是官方模块的一部分,已经包括在nginx中(尽管默认情况下没有构建,因此你你必须重新编译)。

sub_filter  http://toberewritten.com    http://rewritten.com;
sub_filter_once off;
2014-01-09 22:34:45