最近使用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时具体是怎么工作的,谢谢了。