Templates directive causes .html to lose MIME type?

Example scenario:

  • Static website (index.html and about.html)

Example Caddyfile: {
	root .
	templates / .html
	rewrite {
    	if {file} not favicon.ico
    	to {path} {path}/ {path}.html

Example links:

What happens:
Plain HTML source-code appears (i.e. MIME type text/plain), instead of rendering it.

Removing the following line from Caddyfile makes HTML to render correctly:

templates / .html

Is it a bug?

Edit 1: I removed the rewrite directive, the problem persists.

Out of curiosity, what happens when you access

What about with just templates (as opposted to templates / .html)?

MIME text/plain

Same effect {
	root .

Bug report created: https://github.com/mholt/caddy/issues/1417

1 Like

In the meantime, as a workaround, are you able to set the content type manually with the mime directive?

1 Like

I tried with the MIME directive, it partially worked (IIRC it worked with /index and /about, but not /).

Curiously, I’ve been able to fix this MIME issue by running dos2unix on the HTML files :open_mouth:

1 Like

Wait, Caddy thought the html files were text/plain because of line endings…? Interesting to note.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.