This program is for url_rewrite_program
, and concurrency support.
Require: squid-3.4+
go get github.com/rchunping/squid-urlrewrite
url_rewrite_program /path/to/squid-urlrewrite
url_rewrite_children 20 startup=1 idle=1 concurrency=10000
search in this order:
/<program_dir>/squid-urlrewrite.conf
/usr/local/etc/squid-urlrewrite.conf
/etc/squid-urlrewrite.conf
# example
# loglevel
# info: default
# debug: more detail info
# log messages are write to syslog
loglevel debug
# rewrite <regexp> <target>
# redirect <regexp> [301;]<target>
rewrite ^https?://webserver\.domain\.com/file/(\d+)/ http://192.168.1.3:1234/backend/file/read?file_id=$1
redirect ^(https?://)domain\.com/(.*)$ 301;$1www.domain.com/$2
redirect ^(https?://)www\.domain2\.com/(.*)$ $1www2.domain2.com/$2
kill -HUP <pid of squid-urlrewrite>
or
squid -k reconfigure
$ ./squid-urlrewrite
1 http://webserver.domain.com/file/123/test.png // <-- input
1 OK rewrite-url="http://192.168.1.3:1234/backend/file/read?file_id=123" // <-- response
2 http://github.com
2 ERR // <-- It's ok, means no rewrite rule matched.
3 http://domain.com/index.html
3 OK status=301 url="http://www.domain.com/index.html" <-- 301 redirect