Re: [squid-users] Redirecting user based on user agent string or incoming URL

From: Amos Jeffries <squid3_at_treenet.co.nz>
Date: Wed, 10 Feb 2010 18:40:11 +1300

Reuben S. wrote:
> Hi,
>
> I have an existing url_rewrite_program script which redirects the user
> based on the host they came in on. I also want to redirect the user
> to different URLs based on their user agent string (for example, if
> the string has the word "iphone" in it). Does anyone know how I'd
> accomplish this with a single url_rewrite_program? I've checked out a
> few squid options, but I haven't found what I'm looking for yet.
> Should I be using urlgroups or something?
>
> I've found some information on how to do this, but no details. For
> instance, this email says what I'd like to do is possible, but doesn't
> say how:
>
> http://www.squid-cache.org/mail-archive/squid-users/200803/0802.html
>
> Thanks,
>
> Reuben

Before I start, please reconsider any use of URL re-writing carefully.
It introduces a number of problems that are avoidable by proper use of
HTTP messages.

When Henrik means there is that you can use ACLs to control what
requests get re-written. For example;

  acl iphone browser ...
  url_rewrite_access allow iphone
  url_rewrite_access deny all

... will cause on the requests with User-Agent: header matching the
pattern you enter to be re-written.

Do redirection of ore than one type, you will need something more
sophisticated than just a URL-rewriter.

The best alternative we have is deny_info 'redirecting' requests
matching an ACL to some other URL. For example;

  acl iphone browser ...
  acl site dstdomain www.example.com
  http_access deny site iphone
  deny_info http://iphone.example.com/ iphone

... will redirect any requests made from an iphone agent for
www.example.com to iphone.example.com

NP: deny_info is limited in current Squid to one destination URL..
However if you are willing to use a build of 3.2 (alpha code right now)
you can dynamically generate the deny_info URL and for example change
the domain name but keep the path and other parts of the URL.

A more tricky and complex setup would be to mix external_acl_type helper
with a url-rewrite helper. Where the external_acl_type helper registers
some background key outside Squid indicating that the next URL X from
client IP Y needs to be re-written to Z. Then the URL-rewriter when it
seeks IP Y requesting URL X does the re-write.

Amos

-- 
Please be using
   Current Stable Squid 2.7.STABLE7 or 3.0.STABLE23
   Current Beta Squid 3.1.0.16
Received on Wed Feb 10 2010 - 05:40:20 MST

This archive was generated by hypermail 2.2.0 : Wed Feb 10 2010 - 12:00:05 MST