现在caddy2了不在介绍之前的caddy1语法.
最常用见的就是yii2 、tp 等等这样的伪静态规则
if (!-e $request_filename){
rewrite '^(.*)$' /index.php$1 last;
break;
}
我们想转成caddy2的规则怎么弄呢?官方文档也有不少介绍。
伪静态caddy2介绍:
https://caddyserver.com/docs/caddyfile/directives/rewrite
需要用到匹配器:
https://caddyserver.com/docs/caddyfile/matchers
匹配器有如下:
file
header
header_regexp
host
method
not
path
path_regexp
protocol
query
remote_ip
所有请求重写到foo.html
rewrite * /foo.html
规则看起来和nginx还有点差异,怎么转yii2和tp这类伪静态?

@key0 {
not file
path_regexp key0 '(.*)'
}
rewrite @key0 /index.php{re.key0.1}
要留意空格,都是一个空格。
@key0中 not file 是告诉不存在一个文件时候则重写
伪静态转换工具:https://www.toolnb.com/tools/rewriteTools.html
支持nginx、apache、iis、caddy
程序员工具:https://www.toolnb.com/
Caddy2伪静态规则详解
1585

被折叠的 条评论
为什么被折叠?



