How to Implement Redirects in Squid

Write a simple redirector program such as the following using Perl: #!/usr/bin/env perl $|=1; while () { $url = m/^(*)/; if ($url !~ /^http:\/\/www\.hostname\.com/) { $url =~ s@^http://www\.hostname\.com/(., In your squid.conf file change the...

7 Steps 1 min read Medium

Step-by-Step Guide

  1. Step 1: Write a simple redirector program such as the following using Perl: #!/usr/bin/env perl $|=1; while (<>) { $url = m/^(*)/; if ($url !~ /^http:\/\/www\.hostname\.com/) { $url =~ s@^http://www\.hostname\.com/(.

    *)@http://www.hostname.com/\1@; print "301:$url\n"; } else { print "$url\n"; } }
  2. Step 2: In your squid.conf file change the redirect_program variable

    ,, You'll need to know the path to the squid executable.

    Depending on your operating system and installation, it's most likely at /usr/local/squid/sbin/squid.

    Execute this command on the terminal: /usr/local/squid/sbin/squid
    -k reconfigure
  3. Step 3: it's probably commented out

  4. Step 4: and specify where your redirector_program is

  5. Step 5: ex: /usr/sbin/redirect.pl

  6. Step 6: Make sure that the variable httpd_accel_uses_host_header is set to on or nothing will be redirected.

  7. Step 7: Reload the squid configuration.

Detailed Guide

*)@http://www.hostname.com/\1@; print "301:$url\n"; } else { print "$url\n"; } }

,, You'll need to know the path to the squid executable.

Depending on your operating system and installation, it's most likely at /usr/local/squid/sbin/squid.

Execute this command on the terminal: /usr/local/squid/sbin/squid
-k reconfigure

About the Author

G

Gloria Ward

Committed to making pet care accessible and understandable for everyone.

32 articles
View all articles

Rate This Guide

--
Loading...
5
0
4
0
3
0
2
0
1
0

How helpful was this guide? Click to rate: