Hello!
I’ve made some changes in my website and I need to do some URL redirects: /personal/{post}, /general/{post}, /explanations/{post}, /tutorials/{post}
to /blog/{post}
.
Is there any way to do so?
Thanks
Hello!
I’ve made some changes in my website and I need to do some URL redirects: /personal/{post}, /general/{post}, /explanations/{post}, /tutorials/{post}
to /blog/{post}
.
Is there any way to do so?
Thanks
why not use rewrite
? redir
can not yet capture {post}
part of the url.
rewrite {
r /(general|explanations|tutorials)/(.*)
to /blog/{1}
}
Hey!
Thanks for that. I tried but it is not working (e.g.: https://henriquedias.com/tutorials/mvc-linguagem-php-iv/).
My entire Caddyfile:
http://www.henriquedias.com {
redir https://henriquedias.com{uri}
}
http://henriquedias.com {
redir https://henriquedias.com{uri}
}
https://henriquedias.com {
gzip
root /var/www/henriquedias.com/public/
basicauth /admin user pass
tls ssl/certificate.crt ssl/private.key
errors {
log /var/www/errors.log
404 404.html
}
hugo /var/www/henriquedias.com/
rewrite {
r /(general|explanations|tutorials|personal)/(.*)
to /blog/{1}
}
}
Any idea why?
Does it have something to do with the forward slashes? Do they need to be escaped? (My Go regexp skills are a little rusty.)
I tried replacing it with:
rewrite {
r ^\/(general|explanations|tutorials|personal)\/(.*)
to /blog/{1}
}
But it still doesn’t work :S
Changed it! And works!
rewrite {
r \/(tutorials|personal|explanations|general)\/(.*)
to /blog/{2}
}
Why 2? Because the first captured group is (tutorials|personal|explanations|general)
and not (.*)
.
Thank you all.
Haha oh yeah! Forgot about how that works.
Oh my! Missed that.
Do you really needed to escape /
? Did you try without escaping it ?
No, I haven’t
I think it’s a good idea to always use valid regex anyway.
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.