nginx干净的URL路由器/重写

即时通讯与nginxconfiguration相对简单的重写规则/路由器有困难。

我想要做的是,如果请求目录或文件'主机/我/请求/path[/ [index.php]]'不存在,重写为'主机/我/请求/ path.php'

目前的重写工作如下:

host host/ host/my/request/path 

但不会为:

 host/my/request/path/ 

这是configuration的重写部分:

  location / { try_files $uri/ $uri $uri.php; } 

错误日志将报告:

 Access forbidden by rule, request: "GET /my/request/path/ HTTP/1.0" 

嗯,有没有更好的方法来解决这个问题或摆脱尾随斜线?

编辑,规则更精细:

 host[/] > host/index.php host/index[/] > host/index.php host/my/path[/] > if /path/index.php exists: host/my/path/index.php else host/my/path.php 

解:

https://stackoverflow.com/questions/9557936/nginx-trailing-slash-rewrite-results-in-a-redirect-loop

我补充说

 rewrite ^/(.*)/$ /$1; 

在第一篇文章的规则之前,似乎正在工作。