From 79f00cd7d2b3e2a3c538d8c6cb07b92fd372911c Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Wed, 9 Jan 2019 00:46:17 -0500 Subject: [PATCH] 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). --- Makefile | 2 +- src/redirect-map.php | 69 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 src/redirect-map.php diff --git a/Makefile b/Makefile index 20a9475..5a6786e 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/src/redirect-map.php b/src/redirect-map.php new file mode 100644 index 0000000..800e952 --- /dev/null +++ b/src/redirect-map.php @@ -0,0 +1,69 @@ +. + * + * 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" );