duanpiao6679 2015-06-23 12:57
浏览 65
已采纳

Nginx wordpress url重写,另有规则

I'm new to nginx and I'm configuring my server block. Currently everything works fine but now I'm trying to move my wordpress website that was on an Apache server. On my website I had a rewriting rule that allowed me to access a php page without specifying the .php extension. I had also the wordpress permalink rewriting rule.

Now on nginx, I managed to make them work but only separately:

location / { # Accessing php script without specifying the extension try_files $uri $uri/ $uri.html $uri.php?$query_string; }

...and...

location / { # Wordpress permalinks try_files $uri $uri/ /index.php?q=$uri&$args; }

What I would want to do, is making this two rules work together. I have no idea how to do it and I didn't find anything that corresponded to what I wanted.

Thanks very much !

  • 写回答

2条回答 默认 最新

  • dongshi2458 2015-06-23 20:24
    关注

    If I understand your use case correctly, you should be able to combine the two into one location block like this:

    location / {
      try_files $uri $uri/ $uri.html $uri.php /index.php?q=$uri&$args;
    }
    

    You'll still need a separate location block after that to process PHP. Something like:

    location ~ \.php$ {
      #match actual filename with extension or file not found
      try_files $uri =404;
    
      #... or replace next lines with your preferred PHP processing config
      include fastcgi_params;
      fastcgi_pass unix:/var/run/php5-fpm.sock;
    }
    

    Of course, this is not the complete configuration but hopefully helps with this aspect.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 聚类分析或者python进行数据分析
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号