Unfortunately @HBruijn's quite clever idea of simply making
/generate_204 a directory rather than a file and then using that as the
cgi_prefix with an
index.cgi-file inside it as the
index_page, only works partly. When I open
/generate_204 from the browser myself, it does exactly what I wanted, but only after first returning a redirect to
/generate_204/, which the Android captive portal detection explicitly ignores. So, unfortunately this solution doesn't solve my problem.
Here's the hack-job I've come up with that does seem to work:
Simply don't have a
/generate_204 file at all and instead create a CGI-script in
cgi-bin that handles all erroneous requests that looks like this:
if [ "$REQUEST_URI" == "/generate_204" ]; then
echo "Status: 204 No Content"
echo "Status: 404 Not Found"
echo "Content-Type: text/html"
Then simply add the following to
option error_page /cgi-bin/error.cgi
option cgi_prefix /cgi-bin
list interpreter ".cgi=/bin/ash"
(adjusting file and folder names as needed)
This is definitely not the cleanest solution, and in case there's a way to prevent the redirect and make @HBruijn's idea work, I'll leave the question open for now, since I'd much prefer that.