最近使用nginx搭建wordpress时,使用固定连接->自定义结构->/archives/%post_id%.html,
保存后再读取文章时提示404。
网上搜索方案后,解决方法如下:
在location下添加如下代码:
if (-f $request_filename/index.html){rewrite (.*) $1/index.html break;}if (-f $request_filename/index.php){rewrite (.*) $1/index.php;}if (!-f $request_filename){rewrite (.*) /index.php;}现在的问题就是对这段代码并不是很理解。没有学过php和数据库,对相关概念不是很清楚。
比如我现在访问一篇文章,blog.abc.com/archives/1.html,
此时$request_filename是等于/archives/1.html吗?
然后依次寻找/archives/1.html/index.html,/archives/1.html/index.php,/archives/1.html
此处前两个规则都没有,所以此时url被重写为blog.abc.com/index.php?
然后经由fastcgi交给php解析,查找数据库里的文章返回一个html静态的显示内容?
那此时url为blog.abc.com/index.php,能解析出%post_id%为1的文章吗。
我知道我上面自己的理解应该是错的,所以想问一下这段代码在访问blog.abc.com/archives/1.html时具体是怎么工作的,谢谢了。
在使用nginx搭建wordpress并启用固定连接时遇到404错误。通过在location下添加rewrite规则解决,但对代码理解不透彻。访问/blog.abc.com/archives/1.html时,请求如何被重定向到index.php并由php处理,寻找数据库中的文章内容。寻求代码工作原理的解释。
2624

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



