这是不是对与有版本的wordpress有效我也拿不准,不过,至少我试了,这个方法有效,并且出自wordpress官方支持。或许更早的wordpress未必支持这种方法,但至少从我写文章的这一天起,这个方法是正确的。
将网站做成伪静态页面会提高搜索引擎的收录有先级(网上说的)。所以这个技术有必要了解。
网上可以找到很多使用rewrite的方法实现伪静态。但我测试了一下不是很好用。
至少下面这个在我这里不好用:
location / { index index.html index.htm index.php; root /www/wwwroot/chinaz.com; 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; } }
我这里找到一个方法效果很好并且非常简单:http://nginxlibrary.com/wordpress-permalinks/
It should look like this after the edits :
location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$args;
}
If your blog is in a subfolder (say /blog), you’ll have to add an extra location /blog/
block to your configuration file :
location /blog/ {
try_files $uri $uri/ /blog/index.php?$args;
}
After you have finished making the changes in the configuration file, reload the nginx configuration by :
nginx -s reload
WordPress’ pretty permalinks should work fine now.