I stumbled across caddy a few days ago and was impressed by the ease I could migrate my static site to caddy.
However right now I am struggling with the rewrite of my urls. Mine look like http://example.com/2017/045/03 where 45 is day of year and 03 is post no. 3 that day. Since the directories for a year do not contain any files but folders, I want to redirect “bad” links to my landing page. Well, I think my english is not good enough to tell you what I want so I will give you a few examples:
# request -> file
http://example.com/ -> http://example.com/blog/index.html # this does not work
http://example.com/blog -> http://example.com/blog/index.html # works
http://example.com/blog/2017 -> http://example.com/blog/index.html # works
http://example.com/blog/2017/045/01-> http://example.com/blog/2017/045/01/index.html # works
I got inspired by this topic when I did not get my regex working (calls to my css file at /css/main got redirected as well).
to {uri} /blog/{path}/index.md /blog/index.html
}```
Unforunatelly this does not match a call to ```http://example.com``` and returns a 404...
Does anybody know how to achieve this? Any help will be very much appreciated.
Cheers,
barp
I finally got my Caddyfile working thanks to some hours fiddling around and the very good user guide
But there is always a new “problem” arising and so I was wondering if you could help me with that as I have no idea how to achieve my plan:
The migration of my static content is finished and I want to handle webmentions myself. Therefore I hacked a little python script that accepts a webmention and writes it down into the “front matter” of my markdown posts. My page template will take care of the representation (as I expect at most 2-5 reactions per post this will not kill caddys performance).
Unfortunately I don’t know how to make the interaction between my webmentions endpoint and my python script. The only way I got working was via proxy but I don’t like the idea of a python process running all day doing nothing…
My Caddyfile looks like this:
localhost # just for testing
errors {
log error.log {
size 5 # Rotate after 5 MB
age 30 # Keep rotated files for 30 days
keep 5 # Keep at most 5 log files
}
}
log access.log {
rotate {
size 10 # Rotate after 10 MB
age 14 # Keep log files for 14 days
keep 10 # Keep at most 10 log files
}
}
markdown {
template /default.tpl
template index /index.tpl
}
rewrite {
if {path} not_has /webmention
to {path} /{path}/index.md /index.html
}
proxy /webmention localhost:8000
thanks for the confirmation that my worries were right and this is the way to go. But since Caddy is so awesome I will not ditch it for this small hiccup
Maybe you can help me with another minor thing: See my rewrite rule which I sat up with an “if” as Caddy redirects my “should go to python”-calls to “/index.html” as well. Is this the right way to do it?
rewrite {
if {path} not_has /webmention
to {path} /{path}/index.md /index.html
}
Looks good! That’s how I usually do things.
Only possible improvement would be elimitating bad rewrite logic for hypothetical requests to /foo/bar/webmention - something like if {request} not_has https://example.com/webmention maybe.
Sometimes I wish there were not_starts_with and not_ends_with conditionals