"{{ to }}", {% endfor %} ); $redirects_re = array( '^(?:sysadmin|it|linux-tech-coding|sysadmin-blog)\/?(page.*)?$' => 'category/article/', '^(?:fotography|photoblog)\/?(page.*)?$' => '/category/photo/$1', '^blog\/?(page.*)?$' => '/category/journal/', '^blips\/?(page.*)?$' => '/category/note/$1', '^r\/?(page.*)?$' => '/category/note/$1', '^(?:linux-tech-coding|it|sysadmin-blog|sysadmin|fotography|blips|blog|photoblog|article|journal|photo|note|r)\/((?!page).*)' => '/$1', ); $gone = array( {% for gone in gones %} "{{ gone }}" => true, {% endfor %} ); $gone_re = array( '^cache\/.*$', '^files\/.*$', '^wp-content\/.*$', '^broadcast\/wp-ffpc\.message$', ); function redirect_to($uri) { header('HTTP/1.1 301 Moved Permanently'); if (preg_match("/^https?/", $uri)) $target = $uri; else $target = '{{ site.url }}/'. trim($uri, '/') . '/'; header("Location: ". $target); exit; } function gone($uri) { header('HTTP/1.1 410 Gone'); die(' Gone

This content was deleted.


{{ site.domain }}

'); } function notfound() { header('HTTP/1.0 404 Not Found'); die(' Not found

This was not found.

Please search for it instead.

'); } function maybe_redirect($uri) { if (file_exists("./$uri/index.html")) { redirect_to($uri); } } $uri = filter_var($_SERVER['REQUEST_URI'], FILTER_SANITIZE_URL); $uri = str_replace('../', '', $uri); $uri = str_replace('/feed/', '', $uri); $uri = str_replace('/atom/', '', $uri); $uri = trim($uri, '/'); foreach ($gone_re as $pattern) { if (preg_match(sprintf('/%s/', $pattern), $uri)) { gone($uri); } } foreach ($redirects_re as $pattern => $target) { $maybe = preg_match(sprintf('/%s/i', $pattern), $uri, $matches); if ($maybe) { $target = str_replace('$1', $matches[1], $target); redirect_to($target); } } if (isset($gone[$uri])) { gone($uri); } elseif (isset($redirects[$uri])) { redirect_to($redirects[$uri]); } elseif (preg_match('/^\.well-known\/(host-meta|webfinger).*$/', $uri)) { redirect_to("https://fed.brid.gy/{$uri}"); } elseif (strstr($uri, '_')) { maybe_redirect(str_replace('_', '-', $uri)); } else { notfound(); }