项目二级目录下的index.php使用nginx重写

misaka去年夏天 2016-11-23 02:06:29
我想重写一个www.xxx.com/shuicao/index.php/aaa/bbb.html为www.xxx.com/shuicao/aaa/bbb.html、也就是把网站项目的二级目录(shuicao)的index.php隐藏,我写了这样的重写规则,但是使用www.xxx.com/shuicao/aaa/bbb.html访问的时候,总是会给我定向到www.xxx.com/shuicao/项目下的默认首页(即使我换成www.xxx.com/shuicao/任意字符串,也会定向到首页)。

不知道是不是我的rewrite写错了,还是thinkphp项目的配置问题(我已经配置为URL_MODEL为2,也就是重写模式了)



location / {
index index.html index.htm index.php l.php;
autoindex off;

if (!-e $request_filename)
{
#地址作为将参数rewrite到index.php上。
rewrite ^/(.*)$ /index.php/$1 last;
}
}

location /shuicao/ {
index index.html index.htm index.php l.php;
autoindex off;

if (!-e $request_filename){
rewrite ^/shuicao/(.*)$ /shuicao/index.php/$2 last;
}
}





...全文
340 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
misaka去年夏天 2016-11-23
  • 打赏
  • 举报
回复
解决了,原来是我的正则匹配的$1写成了$2导致的。

写成了$2,根本没有捕捉到$2的正则,所以nginx把url重定向之后,一直在/shuicao/重定向循环。


misaka去年夏天 2016-11-23
  • 打赏
  • 举报
回复
如果我使用www.xxx.com/shuicao/index.php/aaa/bbb.html就没问题的。

21,887

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧