Following is a method to redirect any URL to another URL. for example if you want that when user opens google.com.pk , he must be redirected to google.com.sa , you can use the following simple PHP redirector to fulfill this requirement.
First Add the redirector location in squid.conf
nano /etc/squid/squid.conf
url_rewrite_program /etc/squid/url_redirect.php url_rewrite_children 5
Save & Exit.
Now create the url redirector by
nano /etc/squid/url_redirect.php
#!/usr/bin/php # Syed Jahanzaib / aacable@hotmail.com / https://aacable.wordpress.com # Squid URL Rewrite program : Codes picked from the internet. <?php $temp = array(); while ( $input = fgets(STDIN) ) { // Split the output (space delimited) from squid into an array. $temp = split(' ', $input); // Set the URL from squid to a temporary holder. $output = $temp[0] . "\n"; // Clean the Requesting IP Address field up. $ip = split('/',rtrim($temp[1], "/-")); if (preg_match("/^http:\/\/www.google.com.pk/i", $temp[0])) { $output = "301:http://www.google.com.sa\n"; } echo $output; }
▼
Save & Exit.
Assign execute permission by
chmod +x /etc/squid/url_redirect.php
Now restart / recon squid service and from client end try to open google.com.pk & you will be redirected to google.com.sa transparently :)~
Examples:
▼
Before URL Redirection , squid log showed
101.11.11.161 TCP_MISS/200 71205 GET http://www.google.com.pk/ – DIRECT/74.125.236.120 text/html
After URL Redirection, squid log showed
1 101.11.11.161 TCP_MISS/301 309 GET http://www.google.com.pk/ – NONE/-
101.11.11.161 TCP_MISS/200 74892 GET http://www.google.com.sa/ – DIRECT/74.125.236.127 text/html
.
.
.
Regard’s
Syed Jahanzaib