{"id":164,"date":"2019-07-19T22:35:54","date_gmt":"2019-07-19T22:35:54","guid":{"rendered":"https:\/\/tobyslab.com\/?p=164"},"modified":"2019-07-19T22:39:21","modified_gmt":"2019-07-19T22:39:21","slug":"short-urls-on-a-custom-domain","status":"publish","type":"post","link":"https:\/\/tobyslab.com\/?p=164","title":{"rendered":"Short URLs on a Custom Domain"},"content":{"rendered":"\n<p>I have a custom domain I use for short URLs, tlab.co, which works out to be a lot cheaper than bit.ly for custom domain redirections. While I am in the very early stages of developing the backend system and analytics for the site, I have implemented a very simple Bash script that generates the links and puts them live on the site which I share here.<\/p>\n\n\n\n<p>Customize BASE (the base directory &#8211; usually your web root) and the URI for your server as necessary.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n\nBASE=\"\/usr\/share\/nginx\/html\"\nMYURI=\"https:\/\/tlab.co\/\"\n\n# Check we have two arguments\nif [ \"$1\" == \"\" ] || [ \"$2\" == \"\"  ]; then\n   # We needed two arguments to proceed\n   echo \"Nope\"\n   exit 1;\nfi\n\n# Check if the directory exists\nFILE=\"$BASE\/$1\"\nif [ -d \"$FILE\" ]; then\n   echo \"$FILE already exists\"\n   while true; do\n      read -p \"Do you wish to overwrite this link? \" yn\n      case $yn in\n         [Yy]* ) rm -rf $FILE; break;;\n         [Nn]* ) exit;;\n         * ) echo \"Please answer yes or no.\";;\n      esac\n   done\nfi\n\necho \"Creating new short url\";\necho \"$MYURI$1 => $2\";\n\nmkdir \"$BASE\/$1\"\ncat &lt;&lt;EOT >> \"$BASE\/$1\/index.html\"\n&lt;html xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n  &lt;head>\n    &lt;title>Redirecting...&lt;\/title>\n    &lt;meta http-equiv=\"refresh\" content=\"0;URL='$2'\" \/>\n  &lt;\/head>\n  &lt;body>\n  &lt;\/body>\n&lt;\/html>\nEOT<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I have a custom domain I use for short URLs, tlab.co, which works out to be a lot cheaper than bit.ly for custom domain redirections. While I am in the very early stages of developing the backend system and analytics for the site, I have implemented a very simple Bash script that generates the links and puts them live on the site which I share here. Customize BASE (the base directory &#8211; usually your web root) and the URI for your server as necessary.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":""},"categories":[10],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/tobyslab.com\/index.php?rest_route=\/wp\/v2\/posts\/164"}],"collection":[{"href":"https:\/\/tobyslab.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tobyslab.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tobyslab.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tobyslab.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=164"}],"version-history":[{"count":2,"href":"https:\/\/tobyslab.com\/index.php?rest_route=\/wp\/v2\/posts\/164\/revisions"}],"predecessor-version":[{"id":167,"href":"https:\/\/tobyslab.com\/index.php?rest_route=\/wp\/v2\/posts\/164\/revisions\/167"}],"wp:attachment":[{"href":"https:\/\/tobyslab.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=164"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tobyslab.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=164"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tobyslab.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=164"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}