Redirect URL In Squid Proxy Server

Q: How to redirect a url in squid proxy?

The actual solution for url redirection is "SquidGuard", and i will explain it in coming days.
Here is a small solution for redirecting a url to another url within Squid proxy. 
And its a simple logic, Basically it works as a denying ACL. Squid deny the access to a specified Website and redirect them to a predefined url as an ERROR MESSAGE.  
So this 

Edit the Squid configuration
[root@server ~]# vi /etc/squid/squid.conf
acl lan src                           #client acl for the lan
acl badsites dstdomain                 #to deny ""
deny_info lan                   #Deny with redirect to for lan
http_reply_access deny badsites lan              # Deny badsites to lan
#Add the 4 lines to the squid.conf configuration file, save and exit.

Reload Squid Server with new configuration
[root@server ~]# service squid reload

As a result when a proxy client access to "" the Squid server will deny the access and redirect to as an error message.

Was this helpfull ?


gBloger said...

hi, how do I do this for multi website??
in your example it will redirect all to but

I want redirect
a, b, c to x, y,z
is it possible from squid??


Andres Mansilla said...

In that case you must use in dstdomain a list with all the domains you want to redirect

acl badsites dstdomain "/etc/squid/list"

create the file list and add all the domains that you wanted to be redirected

ammaraihaan said...

First of all thank you Andres, I followed your original post and it fixed my original query. This was to enforce Google Safesearch. This was done by adding the following lines to the squid.conf file:

#client acl for the lan
acl lan src

#to deny ""
acl badsites dstdomain

#Deny with redirect to Google SafeSearch for lan
deny_info lan

#Deny badsites to lan
http_reply_access deny badsites lan

I was wandering if the following command would work:
acl badsites dstdom_regex -i *.google.*

I haven't tested the above yet, but plan to test it later this week.

Tasbir Farid said...

Can I use multiple url to be redirected to multiple site:
for example, will be redirected to to to etc.

Thanks in advance.

Unknown said...

acl a_site dstdomain
acl b_site dstdomain
acl c_site dstdomain
deny_info lan
http_reply_access deny a_site lan
deny_info lan
http_reply_access deny b_site lan
deny_info lan
http_reply_access deny c_site lan

This is just a guess, you may have to create duplicates of lan with different names (eg lan1, lan2, lan3) to prevent message conflicts. In a case like this though I would redirect all to a website with the request URL in a query string, then parse that on a server and redirect from there.

Related Posts Plugin for WordPress, Blogger...

Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Bluehost Coupons