开发者社区> 问答> 正文

WordPress Nginx 伪静态 404

CentOS 6.5,环境使用的是WDCP,今天切换成 Nignx,为了以下伪静态规则,为何只能匹配


www.domain.com/postname/
而不匹配


www.domain.com/postname.html


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;
    }
}

展开
收起
milly 2016-04-18 19:29:18 8207 0
2 条回答
写回答
取消 提交回答
  • 回 1楼dongshan8的帖子
    使用这个规则后和原文说的一样,可以从domain.com/postname/ 跳转到 domain.com/postname.html 但是还是显示404

    -------------------------

    回 3楼dongshan8的帖子
    用的是 WDCP,估计是哪边有问题,我设置的是一样的…默默切换回 Apache,然后内存又暴了…

    -------------------------

    ReWordPress Nginx 伪静态 404
    终于找到可以用的规则了,之前的规则可能是某些设置或 index.php 权限问题导致无法定位到正确的地址,用以下规则解决,遇到同样问题的可以试试。 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;
    }


    2016-04-18 22:33:34
    赞同 展开评论 打赏
  • 旺旺:nectar2。
    楼主您好,

    我现在没有使用 nginx,但为您找到这个文章,里边多了一条规则:

    if (!-d $request_filename){
                    rewrite ^/(.*)(\/)$ http://$host/$1.html permanent;
            }


    您有空时,可测试一下,看是否能成功: http://www.dabu.info/postname-nginxs-rewrite-to-the-wording-of-the-postname-html.html

    -------------------------

    回 2楼(milly) 的帖子
    您好,

    我在Debian 7 系统里安装 nginx 1.2.1 测试 wordpress,

    1. 在 wordpress 后台启用“自定义结构”的固定链接:
    /%postname%.html




    2. 在 nginx 的站点配置文件中,在 server 节中修改为以下的内容:
    try_files $uri $uri/ /index.php?$args;



    3. 回到wordpress前台,可以通过打开postname.html的页面: http://yun.anqun.org/hello-world.html



    -------------------------

    回 4楼(milly) 的帖子
    您好,

    您可以再找找,看看在 wdCP 中的 nginx 配置文件中,是否有重复设置的地方喔。
    2016-04-18 20:07:14
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
《Nginx 代理系统常用手册》 立即下载
CentOS Nginx PHP JAVA 多语言镜像使用手 立即下载
CentOS Nginx PHP JAVA多语言镜像使用手册 立即下载