Caddy 重写和重定向
Caddy rewrite and redir
我有一个棘手的案例。我想在少数情况下总是重定向。我想在请求 www.myWebsite.com/toto.png 时看到 "toto.png",但在请求 www.myWebsite.com/titi 或 www.myWebsite.[= 时也希望看到 "toto.png" 18=]。
在所有其他情况下,我想重定向到 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/
}
我发现了这种可能性:
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
}
}
在 Caddy 2 中,这个问题可以更容易地解决:
rewrite /titi /toto.png
route {
file_server /toto.png
redir https://anotherwebsite.com
}
下周我们将登陆 these improvements Beta 13。
我有一个棘手的案例。我想在少数情况下总是重定向。我想在请求 www.myWebsite.com/toto.png 时看到 "toto.png",但在请求 www.myWebsite.com/titi 或 www.myWebsite.[= 时也希望看到 "toto.png" 18=]。 在所有其他情况下,我想重定向到 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/
}
我发现了这种可能性:
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
}
}
在 Caddy 2 中,这个问题可以更容易地解决:
rewrite /titi /toto.png
route {
file_server /toto.png
redir https://anotherwebsite.com
}
下周我们将登陆 these improvements Beta 13。