{"id":65,"date":"2010-01-20T16:14:24","date_gmt":"2010-01-20T16:14:24","guid":{"rendered":"http:\/\/poojanwagh.opalstacked.com\/techblog\/?p=65"},"modified":"2010-01-23T04:45:54","modified_gmt":"2010-01-23T04:45:54","slug":"using-self-hosted-url-shortener-yourls","status":"publish","type":"post","link":"https:\/\/tech.poojanblog.com\/blog\/hosted-web\/using-self-hosted-url-shortener-yourls\/","title":{"rendered":"Using self-hosted URL shortener YOURLS"},"content":{"rendered":"<h3>Update<\/h3>\n<p>This works better:<br \/>\n[cclN_php]define(&#8216;YOURLS_SITE&#8217;, &#8216;http:\/\/&#8217; . $_SERVER[&#8216;SERVER_NAME&#8217;]);[\/cclN_php]<br \/>\nassuming yourls is installed in the root directory of your web site (<code>http:\/\/foo.bar.com\/<\/code> for example). If otherwise (<code>http:\/\/foo.bar.com\/yourls\/<\/code>) you&#8217;d want:<br \/>\n[cclN_php]define(&#8216;YOURLS_SITE&#8217;, &#8216;http:\/\/&#8217; . $_SERVER[&#8216;SERVER_NAME&#8217;] . &#8216;\/yourls&#8217;);[\/cclN_php]<\/p>\n<h3>Original Post<\/h3>\n<p>I&#8217;m now using <a title=\"Shorten2Ping\" href=\"http:\/\/wordpress.org\/extend\/plugins\/shorten2ping\/\">Shorten2Ping<\/a> to get my post updates from my blogs to Ping.FM (from which it goes to <a href=\"http:\/\/www.linkedin.com\/in\/poojanwagh\">LinkedIn<\/a>, <a href=\"http:\/\/identi.ca\/poojanwagh\">Identi.ca<\/a> and <a href=\"http:\/\/army.twit.tv\/poojanwagh\">army.twit.tv<\/a>).<\/p>\n<p>While setting this up, I noticed that there&#8217;s an option for a self-hosted URL shortener called <a href=\"http:\/\/yourls.org\/\">YOURLS<\/a>. This thing rocks! It shortens URL&#8217;s, collects statistics, and allows custom shortened URL&#8217;s.<\/p>\n<p>I wanted to use the same install (database etc) across all my blogs (poojanblog.com, www.circuitdesign.info, tech.poojanblog.com). WebFaction makes doing so very easy: you can tie any subdirectory of a domain to a specific &#8220;web app&#8221; (UNIX directory). So, for example, both poojanblog.com\/u and www.circuitdesign.info\/u point to the same directory on my web host.<\/p>\n<p>The only issue with this is that YOURLS returns one and only one domain for the shortened URL, set by a PHP define for YOURLS_SITE in includes\/config.php.<\/p>\n<p>Luckily, I found a way around this. I put the following in config.php:<\/p>\n<p>[cclN_php]define(&#8216;YOURLS_SITE&#8217;, dirname($_SERVER[&#8216;REQUEST_URI&#8217;])); \/\/ LOL. Wild guess.[\/cclN_php]<\/p>\n<p>This happens to be taken from <code>includes\/load-yourls.php<\/code> as a fall-back if the YOURLS_SITE isn&#8217;t defined. Basically, it picks up the domain name from the HTTP header.<\/p>\n<div class='wp_likes' id='wp_likes_post-65'><a class='like' href=\"javascript:wp_likes.like(65);\" title='' ><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/tech.poojanblog.com\/blog\/wp-content\/plugins\/wp-likes\/images\/like.png\" alt='' border='0'\/><\/a><span class='text'>Be the first to like.<\/span><\/p>\n<div class='like' ><a href=\"javascript:wp_likes.like(65);\">Like<\/a><\/div>\n<div class='unlike' ><a href=\"javascript:wp_likes.unlike(65);\">Unlike<\/a><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>While setting this up, I noticed that there&#8217;s an option for a self-hosted URL shortener called YOURLS. This thing rocks! It shortens URL&#8217;s, collects statistics, and allows custom shortened URL&#8217;s.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[20],"tags":[15,17,18],"class_list":["post-65","post","type-post","status-publish","format-standard","hentry","category-hosted-web","tag-ping-fm","tag-url-shortener","tag-wordpress"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/tech.poojanblog.com\/blog\/wp-json\/wp\/v2\/posts\/65","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tech.poojanblog.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tech.poojanblog.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tech.poojanblog.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/tech.poojanblog.com\/blog\/wp-json\/wp\/v2\/comments?post=65"}],"version-history":[{"count":6,"href":"https:\/\/tech.poojanblog.com\/blog\/wp-json\/wp\/v2\/posts\/65\/revisions"}],"predecessor-version":[{"id":71,"href":"https:\/\/tech.poojanblog.com\/blog\/wp-json\/wp\/v2\/posts\/65\/revisions\/71"}],"wp:attachment":[{"href":"https:\/\/tech.poojanblog.com\/blog\/wp-json\/wp\/v2\/media?parent=65"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tech.poojanblog.com\/blog\/wp-json\/wp\/v2\/categories?post=65"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tech.poojanblog.com\/blog\/wp-json\/wp\/v2\/tags?post=65"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}