{"id":8652,"date":"2016-12-01T16:10:21","date_gmt":"2016-12-01T15:10:21","guid":{"rendered":"http:\/\/www.wjst.de\/blog\/?p=8652"},"modified":"2016-12-28T10:34:24","modified_gmt":"2016-12-28T09:34:24","slug":"shorten-your-url","status":"publish","type":"post","link":"https:\/\/www.wjst.de\/blog\/sciencesurf\/2016\/12\/shorten-your-url\/","title":{"rendered":"Shorten your URL"},"content":{"rendered":"<p>Based on a <a href=\"#http:\/\/tutorialzine.com\/2013\/12\/quick-tip-create-a-simple-url-shortener-with-10-lines-of-php\/\">tutorialzine.com<\/a> article, I wrote an own URL shortener. Put everything in directory \/s<\/p>\n<p>.htaccess<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nRewriteEngine On\r\nRewriteCond %{REQUEST_FILENAME} !-f\r\nRewriteCond %{REQUEST_FILENAME} !-d\r\nRewriteRule ^(.*)$ \/s\/index.php?$1 &#x5B;last]\r\n<\/pre>\n<p>index.php<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n$links = parse_ini_file('links.ini');\r\n$l=filter_var( $_SERVER&#x5B;'REQUEST_URI'], FILTER_SANITIZE_STRING);\r\n$l=preg_replace ('\/\\\/s\\\/\/','',$l);\r\nif($l!='' &amp;&amp; array_key_exists($l, $links)){\r\n  header('Location: ' . $links&#x5B;$l]);\r\n}\r\nelseif (substr($l,0,4)==&quot;http&quot;) {\r\n  $sl = sprintf( '%04x%04X', mt_rand( 0, 0xffff ), mt_rand( 0,, 0xffff) );\r\n  echo $_SERVER&#x5B;HTTP_HOST]  . '\/s\/' . $sl;\r\n  $out = $sl.' = '.$l;\r\n  file_put_contents('links.ini', $out.&quot;\\n&quot;, FILE_APPEND);\r\n}\r\n<\/pre>\n<p>links.ini<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nGel = &quot;https:\/\/www.google.com\/&quot;\r\n<\/pre>\n<p>Bookmarklet <a href=\"javascript:document.location='https:\/\/www.wjst.de\/s\/'+document.location.href\">ShortenURL<\/a><\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\njavascript: document.location = 'https:\/\/www.www.wjst.de\/s\/' + document.location.href\r\n<\/pre>\n\n<p>&nbsp;<\/p>\n<div class=\"bottom-note\">\n  <span class=\"mod1\">CC-BY-NC Science Surf , accessed 08.04.2026<\/span>\n <\/div>","protected":false},"excerpt":{"rendered":"<p>Based on a tutorialzine.com article, I wrote an own URL shortener. Put everything in directory \/s .htaccess RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ \/s\/index.php?$1 &#x5B;last] index.php $links = parse_ini_file(&#8216;links.ini&#8217;); $l=filter_var( $_SERVER&#x5B;&#8217;REQUEST_URI&#8217;], FILTER_SANITIZE_STRING); $l=preg_replace (&#8216;\/\\\/s\\\/\/&#8217;,&#8221;,$l); if($l!=&#8221; &amp;&amp; array_key_exists($l, $links)){ header(&#8216;Location: &#8216; . $links&#x5B;$l]); } elseif (substr($l,0,4)==&quot;http&quot;) { $sl = sprintf( &#8216;%04x%04X&#8217;, mt_rand( &hellip; <a href=\"https:\/\/www.wjst.de\/blog\/sciencesurf\/2016\/12\/shorten-your-url\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Shorten your URL<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-8652","post","type-post","status-publish","format-standard","hentry","category-computer-software"],"_links":{"self":[{"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/posts\/8652","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/comments?post=8652"}],"version-history":[{"count":12,"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/posts\/8652\/revisions"}],"predecessor-version":[{"id":8741,"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/posts\/8652\/revisions\/8741"}],"wp:attachment":[{"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/media?parent=8652"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/categories?post=8652"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/tags?post=8652"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}