]>
git.ipfire.org Git - thirdparty/squid.git/blob - helpers/url_rewrite/LFS/url_lfs_rewrite.pl.in
11 url_lfs_rewrite [--debug] --local-dir=/var/www/ [options]
15 Direct all request to files who are in a local directory to
16 a local web server hosting this directory.
18 This program uses Squid concurrency support.
30 Directory path under which the scripts searches for files.
34 Scheme to use for the redirected URL.
40 Domain name to use for the redirected URL.
46 URL path to add as prefix for the redirected URL path.
48 If set it must end with a '/'.
50 Default: use the original URL path.
56 * The --local-dir parameter must end with a '/'. Otherwise no
57 file paths will be found.
59 * URL with no filename in the path can match directories on the local
60 filesystem and be wrongly redirected to the local web server.
62 * Any scheme name accepted by the Perl URL library can be used
63 as the --to-scheme parameter. However only schemes supported by
66 * URL containing query-string are not handled well and will not
67 be rewritten even if the base script or file exists on the local
72 url_rewrite_program /path/to/url_lfs_rewrite --local-dir=\var\www\localhost
73 url_rewrite_children 20 startup=1 idle=1 concurrency=25
74 url_rewrite_access deny CONNECT
75 url_rewrite_access deny to_localhost
78 This helper can redirect to any web server but only does so if there is
79 a file matching the URL path segment in the local filesystem. Normal
80 configuration requires a web server running on localhost serving up files
81 from a local disk (eg. \var\www\localhost). Configuration of that web
82 server is not covered here.
86 This program and documentation was written by I<Amos Jeffries <squid3@treenet.co.nz>>
88 Based on prior work in B<rredir.pl> by I<Peter Eisenhauer <pe@pipetronix.de>>.
89 First Version: 26. May 1997
93 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
95 * Squid software is distributed under GPLv2+ license and includes
96 * contributions from numerous individuals and organizations.
97 * Please see the COPYING and CONTRIBUTORS files for details.
101 Bug reports need to be made in English.
102 See http://wiki.squid-cache.org/SquidFaq/BugReporting for details of what you need to include with your bug report.
104 Report bugs or bug fixes using http://bugs.squid-cache.org/
106 Report serious security bugs to I<Squid Bugs <squid-bugs@squid-cache.org>>
108 Report ideas for new improvements to the I<Squid Developers mailing list <squid-dev@squid-cache.org>>
114 The Squid FAQ wiki http://wiki.squid-cache.org/SquidFaq
116 The Squid Configuration Manual http://www.squid-cache.org/Doc/config/
126 # command line parameters
128 my $access_local_dir = undef;
129 my $redirect_scheme = "http";
130 my $redirect_host = "localhost";
131 my $redirect_path = "";
135 'local-dir=s' => \
$access_local_dir,
136 'to-scheme=s' => \
$redirect_scheme,
137 'to-host=s' => \
$redirect_host,
138 'to-path=s' => \
$redirect_path,
141 # flush after every print
145 # Process lines of the form 'channel-ID URL ip-address/fqdn ident method'
146 # See http://wiki.squid-cache.org/Features/AddonHelpers for details
149 my ($cid, $url, $remainder) = split;
152 my $host = lc($url->host);
154 # do not process hosts with unqualified hostnames
155 if ($host !~ /\./ ) {
156 $status = $cid . " ERR message=\"unqualified hostname\"";
157 print "found unqualified hostname.\n" if $debug;
161 # just the file, without any host or path parts
162 # and just in case: lowercase the file name, so you should make sure
163 # all the files in the local dir are only lowercase !!
164 my $file = lc(basename
($url->path));
166 # look if in local dir, if yes redirect
167 if ( $file && -r
$access_local_dir . $file
168 && $file ne '.' && $file ne '..' ) {
170 $url->scheme($redirect_scheme);
171 $url->host($redirect_host);
172 $url->path($redirect_path . $file);
174 $status = $cid . " OK rewrite-url=\"" . $url . "\"";
175 print "file found: " . $file . "\n" if $debug;
177 $status = $cid . " ERR";
178 print "file not found: " . $file . "\n" if $debug;
182 print $status . "\n";