Redirect old posts

We have two sitautions to account for:

  1. Old posts had both uppercase and lowercase letters in slugs; and
  2. Some ids changed.

Lighttpd can't convert to lowercase and having a bunch of separate redirects
in my webserver configuration for the id changes is messy.  So, this script
is intended to be called only when a post contains an uppercase character in
the path.

I had wanted to avoid _any_ sort of dynamic scripts.  Oh well.

All other redirects are handled in the websevrer configuration (which isn't
part of this repo atm).
master
Mike Gerwitz 2019-01-09 00:46:17 -05:00
parent 9916ad55dc
commit 79f00cd7d2
Signed by: mikegerwitz
GPG Key ID: 8C917B7F5DC51BA2
2 changed files with 70 additions and 1 deletions

View File

@ -56,7 +56,7 @@ srcpages = src/index.html src/about.html src/papers.html src/posts.html \
www-pages = $(patsubst src/%, $(www-root)/%, $(srcpages))
www-files = $(www-pages) $(www-root)/style.css $(www-root)/rss.xml $(www-paper) \
$(www-images) $(www-fonts)
$(www-images) $(www-fonts) $(www-root)/redirect-map.php
RSS_N=10
export WWW_URL

View File

@ -0,0 +1,69 @@
<?php
/**
* Redirect old post ("thought") pages
*
* Copyright (C) 2019 Mike Gerwitz
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* This script should only be invoked for post paths containing an uppercase
* character.
*
* When this site migrated away from repo2html, ids were changed to be all
* lowercase. Further, some of the ids changed in other ways. To handle
* that latter case, a manual mapping was created.
*
* This script issues permanent redirects and, for security reasons, works
* only for post pages.
*/
$req_path = strtolower( $_GET[ 'path' ] );
// Abort immediately if this is not a blog post (prevent this script from
// being used for arbitrary redirects)
if ( !preg_match( '#^/\d{4}/\d{2}/#', $req_path ) ) {
http_response_code( 500 );
die( 'Unsupported redirect' );
}
// Map from old to new location
$map = [
"/2012/10/digitizing-books-is-fair-use-author-s-guild-v.-hathitrust" => "/2012/10/digitizing-books-is-fair-use-authors-guild-v-hathitrust",
"/2012/10/getting-too-tired-to-hack-at-23-00" => "/2012/10/getting-too-tired-to-hack-at-2300",
"/2012/10/jailbreaking-and-dcma-eff-touts-victory-fsf-warns-of-failure" => "/2012/10/jailbreaking-and-dcmaeff-touts-victory-fsf-warns-of-failure",
"/2012/10/openwireless.org" => "/2012/10/openwirelessorg",
"/2012/10/the-use-of-trademarks-in-free-software-has-always-been-a-curious-and-unclear" => "/2012/10/trademarks-in-free-software",
"/2012/10/ubuntu-12.10-privacy-amazon-ads-and-data-leaks" => "/2012/10/ubuntu-1210-privacy-amazon-ads-and-data-leaks",
"/2012/11/copyright-reform-you-re-silly" => "/2012/11/copyright-reform-youre-silly",
"/2012/11/u.s.-copyright-alert-system" => "/2012/11/us-copyright-alert-system",
"/2012/11/vlc-s-move-to-lgpl" => "/2012/11/vlcs-move-to-lgpl",
"/2013/04/u.s.-house-passes-cispa" => "/2013/04/us-house-passes-cispa",
"/2013/08/freebsd-clang-and-gcc-copyleft-vs.-community" => "/2013/08/freebsd-clang-and-gcc-copyleft-vs-community",
"/2013/08/windows-8.1-to-display-targeted-advertisements-on-local-system-searches" => "/2013/08/windows-81-to-display-targeted-advertisements-on-local-system-searches",
"/2014/03/re-freebsd-clang-and-gcc-copyleft-vs.-community" => "/2014/03/re-freebsd-clang-and-gcc-copyleft-vs-community",
"/2016/01/google-analytics-removed-from-gitlab.com-instance" => "/2016/01/google-analytics-removed-from-gitlabcom-instance",
"/2016/08/nso-group-pegasus-trident-ios-exploits-targeting-human-rights-activist" => "/2016/08/nso-group-pegasus-tridentios-exploits-targeting-human-rights-activist",
"/2017/06/don-t-force-me-to-use-your-tools-on-the-web" => "/2017/06/dont-force-me-to-use-your-tools-on-the-web",
"/2018/04/when-talking-about-mobile-tracking-don-t-veil-bad-actors-with-blanket-statements" => "/2018/04/when-talking-about-mobile-tracking-dont-veil-bad-actors-with-blanket-statements",
"/2018/10/webmasters-please-don-t-block-tor" => "/2018/10/webmasters-please-dont-block-tor",
];
// Redirect either to the mapped location or to the lowercased location
$dest_path = ( isset( $map[ $req_path ] ) )
? $map[ $req_path ]
: $req_path;
// Permanent redirect
http_response_code( 301 );
header( "Location: $dest_path" );