From: Eric Wong Date: Wed, 19 Aug 2015 19:46:22 +0000 (+0000) Subject: www: redirect /f/$MESSAGE_ID.txt links to /m/$MESSAGE_ID.txt X-Git-Tag: v1.0.0~1039 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=c23a40e9f6ee1af2feeb0275f14dd9f5b7e91f8c;hp=289778885f8155fbd05a54ed4a84aeb724e68b04;p=public-inbox.git www: redirect /f/$MESSAGE_ID.txt links to /m/$MESSAGE_ID.txt 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. --- diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm index be34e1cd..8f069642 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,