From c23a40e9f6ee1af2feeb0275f14dd9f5b7e91f8c Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 19 Aug 2015 19:46:22 +0000 Subject: 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. --- lib/PublicInbox/WWW.pm | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'lib/PublicInbox/WWW.pm') 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, -- cgit v1.2.3-24-ge0c7