In http header there is a field named accept
, so client can specify prefered format.
How can I configure nginx
to return markdown
page in case of plain text request and processed via some markdown implementation in case of html request?

- 111
- 4
1 Answers
A partial solution (and the simplest way) would be through an internal redirect. You would probably want these inside of an error_page
location
, so that it's only activated when the pages are otherwise not found.
error_page 404 = @404;
location @404 {
if ($http_Accept ~ "text/plain") {
rewrite ^ $uri.text-plain break;
}
if ($http_Accept ~ "text/html") {
rewrite ^ $uri.text-html break;
}
location ~ \.text-plain$ {
…
}
location ~ \.text-html$ {
…
}
}
This would not take into the account the priorities that are specified in the Accept
header, and, also, the explicit example of "text/plain" and "text/html" might as well be somewhat useless in existing browsers — I'm not sure which user-agents would specify text/plain
in their Accept
header.
In the old days, Accept
was useful for deciding whether to serve .gif
or .png
images, but not anymore nowadays — it is now deemed that all browsers have and always has supported png images, and sending the extra bytes in the accept header is not worth the extra traffic, so, for example, Mozilla no longer Accept
's image/png
explicitly, and most other browsers probably follow suit, too.

- 13,848
- 9
- 54
- 76