Home  >  Article  >  Backend Development  >  Wordpress Nginx 伪静态实现 www.domain.com/postname.html?

Wordpress Nginx 伪静态实现 www.domain.com/postname.html?

WBOY
WBOYOriginal
2016-06-06 20:11:071127browse

Wordpress Nginx 伪静态实现 www.domain.com/postname.html?

最近由于阿里云主机内存过低,使用 Apache 时不时抽风,所以换成 Nginx,不过伪静态规则难倒了我。按照官网介绍主要添加以下规则即可。

<code>location / {
    try_files $uri $uri/ /index.php?$args;
}</code>

不过实测只能支持

<code>//支持这类目录形式
http://www.domain.com/category/tag
http://www.domain.com/category/postname

//不支持带后缀
http://www.domain.com/category/postname.html</code>

现在访问带后缀的地址都是 404,如果把固定链接的形式改成截图中的目录形式或?p=id都是正常访问,请问以上有错么?或者还需要哪些方面的设置?

回复内容:

Wordpress Nginx 伪静态实现 www.domain.com/postname.html?

最近由于阿里云主机内存过低,使用 Apache 时不时抽风,所以换成 Nginx,不过伪静态规则难倒了我。按照官网介绍主要添加以下规则即可。

<code>location / {
    try_files $uri $uri/ /index.php?$args;
}</code>

不过实测只能支持

<code>//支持这类目录形式
http://www.domain.com/category/tag
http://www.domain.com/category/postname

//不支持带后缀
http://www.domain.com/category/postname.html</code>

现在访问带后缀的地址都是 404,如果把固定链接的形式改成截图中的目录形式或?p=id都是正常访问,请问以上有错么?或者还需要哪些方面的设置?

终于找到可以用的规则了,之前的规则可能是某些设置或 index.php 权限问题导致无法定位到正确的地址,用以下规则解决了。

<code>rewrite ^.*/files/(.*)$ /wp-includes/ms-files.php?file=$1 last;
if (!-e $request_filename) {
    rewrite ^.+?(/wp-.*) $1 last;
    rewrite ^.+?(/.*\.php)$ $1 last;
    rewrite ^ /index.php last;
}</code>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn