<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Tetrahedra &#187; bit.ly</title>
	<atom:link href="http://tetrahedra.co.uk/tag/bit-ly/feed/" rel="self" type="application/rss+xml" />
	<link>http://tetrahedra.co.uk</link>
	<description>Digital design and development</description>
	<lastBuildDate>Sat, 04 Feb 2012 13:56:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>An alternative bit.ly redirector</title>
		<link>http://tetrahedra.co.uk/bit-ly/</link>
		<comments>http://tetrahedra.co.uk/bit-ly/#comments</comments>
		<pubDate>Mon, 05 Apr 2010 12:49:33 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[bit.ly]]></category>
		<category><![CDATA[bit.ly proxy]]></category>

		<guid isPermaLink="false">http://tetrahedra.co.uk/?p=131</guid>
		<description><![CDATA[For some reason I was in the house by myself one late winter evening when this request from Owen popped into my Twitter feed. The context is that there are a number of countries and organisations that for some reason block redirectors such as bit.ly. Ethiopia, where Owen lives, was one until very recently [until [...]]]></description>
			<content:encoded><![CDATA[<p>For some reason I was in the house by myself one late winter evening when this request from Owen popped into my Twitter feed.</p>
<p><a href="http://tetrahedra.co.uk/wp-content/uploads/Screen-shot-2010-04-05-at-12.36.19.png"><img src="http://tetrahedra.co.uk/wp-content/uploads/Screen-shot-2010-04-05-at-12.36.19-300x163.png" alt="" title="Tweet from Owen Barder - Could somebody build a bitly proxy? I'd put a different IP address for bitly into my hosts file and that servers would translate bitly urls?" width="300" height="163" class="aligncenter size-medium wp-image-136" /></a></p>
<p>The context is that there are a number of countries and organisations that for some reason block redirectors such as bit.ly. Ethiopia, where Owen lives, was one until very recently [until just after I'd written this solution!]. I like a &#8220;how do I do that&#8221; type challenge and I had nothing much better to do that evening. So I wrote an experimental bit.ly proxy.</p>
<p>The steps:</p>
<p><strong>Step 1:</strong> Set up a hosting account with a dedicated IP address. I needed the dedicated IP address to paste into my hosts file, and this is possible through my host, <a href="http://www.bluehost.com">BlueHost.com</a></p>
<p><strong>Step 2:</strong> In the root of the hosting site, I set up .htaccess to send all 404 errors to index.php (but could be any file if you wanted to set it up on your site). The contents of the .htaccess file:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="unix" style="font-family:monospace;">ErrorDocument 404 /index.php</pre></td></tr></table></div>

<p><strong>Step 3:</strong> Download the <a href="http://classes.verkoyen.eu/bitly/">bitly PHP class</a> written by Tijs Verkoyen.  This is a PHP wrapper on the bit.ly API. Put the class into the root of the site.</p>
<p><strong>Step 4:</strong> Register for a free bit.ly user account and apiKey by signing up at <a href="http://bit.ly/account/register">http://bit.ly/account/register</a>.</p>
<p><strong>Step 5:</strong> Edit index.php to include the following simple PHP code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">/*
 * Test page to lengthen bit.ly urls directly
 * 1.0  11/03/2010  JA  Initial prototype
 *
 */</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//build the full bit.ly url from calling url</span>
<span style="color: #000088;">$reqUri</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;REQUEST_URI&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$bitUrl</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://bit.ly&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$reqUri</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// require bitly class</span>
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'bitly.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// create instance of bit.ly class</span>
<span style="color: #000088;">$bitly</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Bitly<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'mybitlyapilogin'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'mybitlyapikey'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//replace the tags with your bit.ly api login and key</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// get original url from the shortened version</span>
<span style="color: #000088;">$longUrl</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$bitly</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">expand</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$bitUrl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//redirect the page</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Location:<span style="color: #006699; font-weight: bold;">$longUrl</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>This code picks up the REQUEST_URI (the bit after the /) and appends to http://bit.ly, then uses the bitly.php class to return the expanded URL, and simply redirects to the target page. With a bit of editing this could be down to 5 lines of code. The secret is to use the bitly.php class to access the bit.ly api.</p>
<p><strong>Step 6:</strong> Modify your hosts file to include the following line:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="unix" style="font-family:monospace;"> #this should be the full IP address of your site - replace x with numbers!
70.40.xxx.xxx   bit.ly</pre></td></tr></table></div>

<p>(in OS X, you edit the hosts file using Terminal and the command <code>sudo nano /private/etc/hosts</code>)</p>
<p>And now all your bit.ly traffic will be redirected through your own site, thus avoiding any IP blockages of bit.ly itself.</p>
<p>As you&#8217;ll have noticed, there&#8217;s no validation, error checking or anything fancy at this stage. But that&#8217;s for another day, if anyone really needs it!</p>
]]></content:encoded>
			<wfw:commentRss>http://tetrahedra.co.uk/bit-ly/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

