cgit is great, but by default when you click on a PDF file in a repository content listing it will show you a
hexdump of the file. You can access the actual file by clicking the "plain" link on top of the listing, but that's
not only annoying, for large PDF files rendering the hexdump can also hang browser tabs.
I found a quick and easy solution to this problem, which I'm documenting here because it seems nobody on the
internet has really done this before, and the usual AI assistants (ChatGPT and Claude) are both deeply confused.
You just add a simple rewrite rule to your nginx config that 302-redirects requests to /tree/.../foobar.pdf to
/plain/.../foobar.pdf. Here's the rule, make sure you put them in your nginx config before the location directive
proxying requests to cgit.
location ~ ^/([^/]+)/tree/(.*\.pdf)$ {
return 302 /$1/plain/$2;
}