From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-3.3 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, RP_MATCHES_RCVD,URIBL_BLOCKED shortcircuit=no autolearn=unavailable version=3.3.2 X-Original-To: meta@public-inbox.org Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 3E10F1F8B3 for ; Wed, 19 Aug 2015 19:51:54 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH] www: redirect /f/$MESSAGE_ID.txt links to /m/$MESSAGE_ID.txt Date: Wed, 19 Aug 2015 19:51:54 +0000 Message-Id: <1440013914-27044-2-git-send-email-e@80x24.org> List-Id: Some people (e.g. myself :p) may try to guess URLs and hit a 404. Redirect to the /m/ version. Note: we prefer to redirect to canonical URLs to improve caching. --- lib/PublicInbox/WWW.pm | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm index be34e1c..8f06964 100644 --- a/lib/PublicInbox/WWW.pm +++ b/lib/PublicInbox/WWW.pm @@ -58,6 +58,10 @@ sub run { my $sp = $2; invalid_list(\%ctx, $1) || get_subject_path(\%ctx, $cgi, $sp); + } elsif ($path_info =~ m!$LISTNAME_RE/f/\S+\.txt\z!o) { + invalid_list_mid(\%ctx, $1, $2) || + redirect_mid_txt(\%ctx, $cgi); + # convenience redirects, order matters } elsif ($path_info =~ m!$LISTNAME_RE/(m|f|t|s)/(\S+)\z!o) { my $pfx = $2; @@ -231,6 +235,15 @@ sub redirect_mid { do_redirect($url . ".html$anchor"); } +# only hit when somebody tries to guess URLs manually: +sub redirect_mid_txt { + my ($ctx, $cgi, $pfx) = @_; + my $listname = $ctx->{listname}; + my $url = self_url($cgi); + $url =~ s!/$listname/f/(\S+\.txt)\z!/$listname/m/$1!; + do_redirect($url); +} + sub do_redirect { my ($url) = @_; [ 301, -- EW