A quick and dirty proxy that (nearly) anyone can do
So we were looking for some hosting in the states for one of our sites, and we were frustrated that all the AdWords on Google.com were geotargeted to our UK IP address. So, I came up with dirty little hack to get the pages we wanted via one of our US servers, without the need to mess around with my browser settings.
You need:
- A domain that you can add wildcard DNS entries to
- An Apache hosting account that will accept a wildcard ServerAlias in the VHost directive. Or IP-based hosting would do it.
- .htaccess support
- The Apache modules mod_proxy and our old favourite, mod_rewrite
Not too much to ask, I’d say. You can definitely get this on any Managed hosting deal, whether you have root or not.
All that you need to do is:
- Pick a domain to use. For this example we’ll be using “example.com”, and so as not to mush up an entire domain, we’ll use the sub “proxy.example.com”
- Add an appropriate DNS entry such that
*.proxy.example.compoints to your server - Set up your server so that one of your VHosts picks up
*.proxy.example.com - Stick this in your .htaccess and smoke it:
[code]RewriteEngine On
RewriteBase /
RewriteRule ^_magic_/(.*)\.proxy\.example\.com/(.*)$ http://$1/$2 [P]
RewriteRule ^(.*)$ /_magic_/%{HTTP_HOST}/$1[/code]
Note: Don’t forget to put your domain in to line 3
Now all you need to do is stick “.proxy.example.com” on the end of the domain bit of any URL you want to visit, eg:
- http://www.google.com.proxy.example.com/search?hl=en&q=dedicated+servers
- http://httpd.apache.org.proxy.example.com/docs/2.0/mod/mod_rewrite.html#rewriterule
This works a bit like the Coral CDN, where you place “.nyud.net:8080″ on the end of your host.
Warning: This is vulnerable to HTTP redirection (301, 302) – eg if you visit http://google.com.proxy.example.com/ you are redirected to http://www.google.com/ by Google’s host canonicalisation.
Anyone wondering what that script does? Well I’ll walk you through it line-by-line:
1, 2: Set up mod_rewrite
Line 4: This is where the rewriting starts (because the first one is skipped initially). This line turns something like “http://foo.com.proxy.example.com/bar.html” into “http://foo.com.proxy.example.com/_magic_/foo.com.proxy.example.com/bar.html“. We do this because we want to rewrite on the Host: header, which mod_rewrite isn’t designed to do. To enable us to do this we artificially place the Host: header, represented as %{HTTP_HOST}, into the URL-path.
Line 3: This line matches the changes made by line 4, to allow us to match out what we want from ${HTTP_HOST} and construct a URL to redirect to. The [P] flag causes this line to by carried out by the proxy module.
Easy, yeah? I don’t know why you didn’t think of it before.

maherphil 1911 days ago
http://helpwebmasters.comgreat post Dave! u da’ man!
Tito 1911 days ago
I believe you can just add &gl=us to the end of the search URL and you can watch the ads for the US.
At least that´s what I´ve tried…
Krunal 1910 days ago
http://www.place-info.orgAmazing post,
Great trick mate… Actually i didnt got 100% of that i can say i didnt got 50% but seriously it seems great trick i would try someday but before that i would have to learn about DNS enteries and .htaccess
Thanx for sharing
Mart 1910 days ago
&gl=us, &gl=uk, &gl=ca and so on. i think those are a little easier to use….
DaveN 1909 days ago
I agree mart but what about the serps
..
DaveN
Rob Haswell 1909 days ago
Or generally finding out if you’re being geotargeted.
Brian Mark 1905 days ago
http://brianmark.blogspot.com/Very cool idea about the SERPs. Not that I’m that concerned about my sites right now in other countries, but I could see that coming into play here before too long.
led display 1351 days ago
http://www.chipshow.comReally a good use of it!
David Raning 1198 days ago
I use these sites for web proxies when I want to get on myspace at work Bypass Site also Facebook Proxy and lastly Sneaky Proxy