1

我有一个棘手的案例。我想在少数情况下总是重定向。当我请求 www.myWebsite.com/toto.png 时,我想看到“toto.png”,而且当我请求 www.myWebsite.com/titi 或 www.myWebsite.com/TITI 时也想看到。在所有其他情况下,我想重定向到 www.anotherWebsite.com/。

这里我当前的配置不起作用:/

www.myWebsite.com{
  tls server@myWebsite.com
  root /var/www/html/
  rewrite / /anotherWebsite
  rewrite /titi /toto.png
  redir /anotherWebsite https://www.anotherWebsite.com/
}
4

2 回答 2

1

我发现了这种可能性:

www.myWebsite.com, myWebsite.com {
  tls server@myWebsite.com
  root /var/www/html/website
  rewrite {
    if {path} is /titi 
    if {path} is /TITI
    if_op  or
    to /toto.png
  }
  rewrite {
    # Check for a file, then a folder
    # If neither exists, we would usually issue a 404
    # Instead, here we rewrite to /anotherWebsite
    to {path} {path}/ /anotherWebsite
  }
  redir {
    # /anotherWebsitewould usually still issue a 404
    # So manually redir from this path if it was rewritten to
    if {rewrite_uri} is /anotherWebsite
    if {path} is /
    if_op  or
    # Modify the destination and status as required
    / https://www.anotherWebsite.com
  }
}
于 2019-12-13T10:54:33.023 回答
1

在 Caddy 2 中,这个问题可以更容易地解决:

rewrite /titi /toto.png
route {
    file_server /toto.png
    redir https://anotherwebsite.com
}

我们将在下周的 beta 13中实现这些改进。

于 2020-01-09T20:52:03.670 回答