Mike Gerwitz

Free Software Hacker+Activist

aboutsummaryrefslogtreecommitdiffstats
blob: 800e952ba64313570638697d8e8ccda8cbd14e18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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" );