user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
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	[thread overview]
Message-ID: <1440013914-27044-2-git-send-email-e@80x24.org> (raw)

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


                 reply	other threads:[~2015-08-19 19:51 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1440013914-27044-2-git-send-email-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

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).