Nginx 到 Caddy2 规则迁移 - 将 if (!-e $request_filename) 转换为 rewrite
Nginx 到 Caddy2 规则迁移 - 将 if (!-e $request_filename) 转换为 rewrite
以下是如何将 Nginx 中的 if (!-e $request_filename) 规则迁移到 Caddy2 中的示例。
Nginx 规则:
if (!-e $request_filename){
rewrite ^(.*)$ /index.php?s=$1 last; break;
}
Caddy2 规则:
rewrite {
if {path} not_match "^/index.php"
to {path} /index.php?s={uri}
}
说明:
- Nginx 中的
if (!-e $request_filename)用于判断请求的文件是否存在,如果不存在则进行重写。 - Caddy2 中的
rewrite语法可以实现类似的逻辑。 not_match表示不匹配,{path}表示当前请求路径,{uri}表示当前请求的 URI。
Caddy2 规则解释:
if {path} not_match "^/index.php": 判断当前请求路径是否与^/index.php匹配。如果匹配,则表示请求的是index.php文件,不需要进行重写。to {path} /index.php?s={uri}: 如果不匹配,则将当前请求路径重写为/index.php?s={uri},其中{uri}表示当前请求的 URI,用于传递请求路径信息。
通过这种方式,可以将 Nginx 中的 if (!-e $request_filename) 规则迁移到 Caddy2 中,实现相同的功能。
原文地址: https://www.cveoy.top/t/topic/nS2k 著作权归作者所有。请勿转载和采集!