I am experimenting with the markdown
capacities of Caddy and have a problem with .md
and .html
files being served at the same time.
Since I did not want my pages to end with .md
(http://example.com/hello.md
), I rewrite .html
URLs to .md
ones:
http://localhost:9998 {
root /www
markdown / {
template default.html
}
rewrite / {
r ^(.*)\.html
to {1}.md
}
}
This is fine, http://example.com/hello.html
and http://example.com/hello.md
point to the same page as expected.
This setup, however, means that I cannot have standalone .html
pages anymore (as they would be rewritten to a non-exiting .md
page).
Is there a way to say “rewrite to .md
except if the file actually exists, in which case do not do any rewrite” (or rewrite to itself if that helps)?
I have doubts whether my setup is reasonable (rewrite .html
pages to .md
) and whether having bare URLs (http://example.com/hello
) which would be picked up as .md
files via the ext directive would not be a wiser approach (it probably would).
Nevertheless, the question on conditional rewrite based on the existence of a file could be useful.