]> Sergey Matveev's repositories - public-inbox.git/commitdiff
www: redirect with query string
authorEric Wong <e@80x24.org>
Sat, 2 Jan 2016 23:13:18 +0000 (23:13 +0000)
committerEric Wong <e@80x24.org>
Sat, 2 Jan 2016 23:13:18 +0000 (23:13 +0000)
We use query strings for search and index pages, so
we should not drop them if somebody types a URL by hand
and omits the trailing slash.

lib/PublicInbox/WWW.pm

index ee414e85d1d5a9442d6a34281df43834e0753cea..b4c050b1069286e7bfb33e5b4e38a19f3b1fcc7e 100644 (file)
@@ -358,15 +358,19 @@ sub r301 {
        my ($ctx, $listname, $mid, $suffix) = @_;
        my $cgi = $ctx->{cgi};
        my $url;
+       my $qs;
        if (ref($cgi) eq 'CGI') {
                $url = $cgi->url(-base) . '/';
+               $qs = $cgi->query_string;
        } else {
                $url = $cgi->base->as_string;
+               $qs = $cgi->env->{QUERY_STRING};
        }
 
        $url .= $listname . '/';
        $url .= (uri_escape_utf8($mid) . '/') if (defined $mid);
        $url .= $suffix if (defined $suffix);
+       $url .= "?$qs" if $qs ne '';
 
        [ 301,
          [ Location => $url, 'Content-Type' => 'text/plain' ],