Hello!
Sorry for the repost from Github issue, but the issue is closed, and I’m afraid, nobody cares.
I ran single language blog with URLs like: /posts/<title>/, but now blog became multilanguage, and URLs changed to /en/<title>/, /ru/<title>/ and so on.
Default language is Russian, so, for now, rewrite looks like:
rewrite /posts {
r (.*)
to /ru{1}
}
This allows me to serve links from the wild internet, but I have a problem with Google: it gets angry when /posts/pyat-samyh-poleznyh-statey-bloga-amplifera/ and /ru/pyat-samyh-poleznyh-statey-bloga-amplifera/ has the same content and I need 301 here.
Not ideal. But it works for the moment to resolve your problem.
@matt: I think this issue has occurred because of the need to separate the responsibilities of the redir and rewrite directives. I think its worth discussing how to overcome this limitation and what the best solution is.
Since we have status on rewrite should we just add support for 3xx errors? I also noticed the if-matcher on redir is broken in some manner. Perhaps its easier to deprecate that in favor of rewrite with status and only use redir for simple 1-to-1 redirects?
Try this Caddyfile for redir bug.
localhost:8080
redir 301 {
if {uri} starts_with /posts
/ru/{uri}
}
Running curl -I http://localhost:8080/aaaa against this matches and redirects to /ru/aaaa same goes for if you try a condition with if {uri} match ^/posts/(.*). It seem’s as though the result of the conditional matcher is being ignored.