VeryNginx icon indicating copy to clipboard operation
VeryNginx copied to clipboard

怎么写一个wordpress的rewrite,并且要排除某些url

Open MrTonyDu opened this issue 9 years ago • 12 comments

MrTonyDu avatar Aug 24 '16 09:08 MrTonyDu

Hi,我不清楚 wordpress 需要怎样的 rewrite,你可以具体描述一下么?

alexazhou avatar Aug 25 '16 08:08 alexazhou

下面是我给wordpress网站加的rewrite: location / { if (-f $request_filename/index.html){ rewrite (.) $1/index.html break; } if (-f $request_filename/index.php){ rewrite (.) $1/index.php; } if ($request_filename ~ /lua){ break; } if ($request_filename ~ /getPCount){ break; } if ($request_filename ~ /verynginx){ break; } if (!-f $request_filename){ rewrite (.*) /index.php; } } 加了上面的rewrite后,vn的filter运行有问题,并不能阻断请求,而是会进到我在nginx.conf中加的rewrite中

MrTonyDu avatar Aug 25 '16 08:08 MrTonyDu

还有就是使用vn的rewrite后,好像并不会重新去匹配server中配置的location,新手,描述问题可能不恰当,见谅

MrTonyDu avatar Aug 25 '16 08:08 MrTonyDu

这里用到了

 if( -f filename )

的指令来判断文件是否存在,然后决定是否进行 rewrite,作用和 try_file 一样 VN 目前还不能处理 try_file 😢,所以不能根据文件是否存在进行 rewrite,只能进行固定的 rewrite。 建议目前先把这样的 rewrite 指令写在 nginx.conf 中,VN 的配置和 Nginx 的配置是可以共存的。

alexazhou avatar Aug 25 '16 08:08 alexazhou

你说的其他问题

  • 加了上面的rewrite后,vn的filter运行有问题,并不能阻断请求,而是会进到我在nginx.conf中加的rewrite中
  • 使用vn的rewrite后,好像并不会重新去匹配server中配置的location

我没有太明白,这是一个问题的两种描述,还是分别描述了两个问题呢?

可以再说详细一点,或者给个例子么?

alexazhou avatar Aug 25 '16 08:08 alexazhou

在我配置的rewrite下面有这样一个配置 location ~ .*.php$ { fastcgi_pass unix:/tmp/php-cgi-tony-ourmemory.org.sock; fastcgi_index index.php; include fcgi.conf; fastcgi_param DOCUMENT_ROOT /home/wwwroot/tony/domain/ourmemory.org/web$subdomain; fastcgi_param SCRIPT_FILENAME /home/wwwroot/tony/domain/ourmemory.org/web$subdomain$fastcgi_script_name; }, 我通过vn来rewrite到/index.php后直接下载index.php了

MrTonyDu avatar Aug 25 '16 08:08 MrTonyDu

明白你的问题了。

我找时间配个环境验证下看看

alexazhou avatar Aug 25 '16 08:08 alexazhou

  • 加了上面的rewrite后,vn的filter运行有问题,并不能阻断请求,而是会进到我在nginx.conf中加的rewrite中

这里是这个意思: 我在vn中的filter中有 image 但是我访问http://host/.git会进入到 if (!-f $request_filename){ rewrite (.*) /index.php; } 这个规则

MrTonyDu avatar Aug 25 '16 09:08 MrTonyDu

应该是有限nginx 自带的规则然后才走lua的规则吧 也就是(verynginx配置的)这么理解对吗, 作者.

mlboy avatar Sep 02 '16 19:09 mlboy

Nginx 执行分成几个阶段 其中比较重要的有 Rewrite , Access @mlboy

Rewrite 阶段在 Access 前面

执行顺序是:

Nginx Rewrite -> VeryNginx Rewrite -> Nginx aceess -> VeryNginx Access

所以 VN 规则中配置的 rewrite 是在 Nginx 自己的 rewrite 后执行的

alexazhou avatar Sep 03 '16 06:09 alexazhou

@alexazhou 那这种方法 作者建议 我们怎么操作呢 现在大多数phper 写的程序都是需要 伪静态

drcayman avatar Sep 04 '18 01:09 drcayman

@MrTonyDu 你后面是怎么解决的

drcayman avatar Sep 04 '18 01:09 drcayman