首页 > 解决方案 > 球童重写和重新分配

问题描述

我有一个棘手的案例。我想在少数情况下总是重定向。当我请求 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/
}

标签: reverse-proxycaddycaddyfile

解决方案


我发现了这种可能性:

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
  }
}

推荐阅读