Nginx下wordpress 固定链接更改后404问题解决

安装好wordpress后默认文章固定链接后缀是 ?p=xx之类的,这样的链接虽然挺简洁,但对SEO不利。

在后台自定义固定链接后,打开网站除首页外,其他页面都是404。这是由于没有设置好Nginx对wordpress的rewrite规则,google了一些解决办法,说的都是要在Nginx的配置文件写入

server{      location / {      try_files $uri $uri/ /index.php?$args;    }    }  

但是写上以上代码仍然不起作用。于是google到Nginx官网上对于wordpress的rewrite规则说明,照着例子改了自己的Nginx配置,参考如下

upstream php {          server unix:/tmp/php-cgi.socket;          server 127.0.0.1:9000;  }    server {      listen 80;      server_name www.zhenglinbo.com zhenglinbo.com;        root /var/www/blog;      index index.html index.htm index.php;        location / {          try_files $uri $uri/ /index.php?$args;        }        location ~ .php$ {                  #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini                  include fastcgi.conf;                  fastcgi_intercept_errors on;                  fastcgi_pass php;          }        location ~* .(js|css|png|jpg|jpeg|gif|ico)$ {                  expires max;                  log_not_found off;          }        error_page 404 /error/index.html;          location = /40x.html {      }    }  

成功!使用自定义的文章固定链接为 /post-%post_id%.html 。

附Nginx官网对wordpress的rewrite规则说明:https://www.nginx.com/resources/wiki/start/topics/recipes/wordpress/

原文出处:zhenglinbo -> http://www.zhenglinbo.com/post-63.html

相关推荐

发表回复

房先生
我们将24小时内回复。
2024-07-13 09:25:42
您好,有任何疑问请与我们联系!
您的工单我们已经收到,我们将会尽快跟您联系!
[加我微信]
chaoneo
注:点击复制微信号并打开微信APP,添加好友后进行聊天。
[电话联系]
13585372227
[电子邮件]
chaoneo@163.com
取消

选择聊天工具: