【问题标题】:Pretty urls using nginx and wordpress使用 nginx 和 wordpress 的漂亮网址
【发布时间】:2020-07-14 06:37:58
【问题描述】:

我需要在现有的 WP 网站上介绍漂亮的网址:

/foo

应该解释为

/index.php?page_id=5&param=foo

我试过了,在我的服务器块中:

location ~ \.php$ {
    try_files $uri =404;
    include fastcgi_params;
    # other fastcgi stuff ...
}
location / {
    rewrite /foo /index.php?page_id=5&param=foo last;
    try_files $uri $uri/ /index.php?$args;
}

但是 wordpress 正在重定向 (301) 到:

/foo-another-post-title-with-same-prefix

我错在哪里以及如何调试? 谢谢

【问题讨论】:

    标签: wordpress nginx url-rewriting


    【解决方案1】:
    location /foo {
          rewrite ^ /index.php?page_id=5&param=foo last;
    }
    

    应该做的工作:)

    【讨论】:

      【解决方案2】:

      基本上永久链接是通过

      获得的
      location / {
          index index.php index.html index.htm;
          try_files $uri $uri/ /index.php?$args;
      }
      

      在进行故障排除时,您可以enable rewrite_log:

      rewrite_log on; # http block
      

      还有set loglevelnotice

      error_log /var/log/nginx/error.log notice;
      

      【讨论】:

        猜你喜欢
        • 2011-02-04
        • 1970-01-01
        • 1970-01-01
        • 2011-09-19
        • 2014-04-22
        • 2012-03-07
        • 1970-01-01
        • 2013-03-26
        • 2017-07-27
        相关资源
        最近更新 更多