* [PATCH] www: redirect /f/$MESSAGE_ID.txt links to /m/$MESSAGE_ID.txt
@ 2015-08-19 19:51 Eric Wong
0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2015-08-19 19:51 UTC (permalink / raw)
To: meta
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2015-08-19 19:51 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-19 19:51 [PATCH] www: redirect /f/$MESSAGE_ID.txt links to /m/$MESSAGE_ID.txt Eric Wong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).