2

我正在尝试在运行 Nginx 的 WordPress 网站中重写 URL,以便将最后一个子目录转换为 GET 参数:

http://mydomain/property/aid/1234/http://mydomain/property/?aid=1234/

我在 WordPress 中尝试过add_rewrite_rule,但它没有工作,因为它没有创建新$_GET条目。

然后我尝试了以下 Nginx 规则:

rewrite ^(/property/.*)/aid/(.*)$ /$1/?aid=$2 break;

这似乎根本没有效果。

有什么建议么?

4

1 回答 1

0

假设文档根是/www/yourproject/public. 那么 PHP-FPM 的配置可能如下所示:

rewrite "^/property/aid/([0-9]+)$" /property/?aid=$1 break;

location /property/ {
  root            /www/yourproject/public;
  fastcgi_pass    unix:/tmp/php-fpm-yourproject.sock;
  fastcgi_index   index.php;
  include         fastcgi_params;
}

在此配置中,请求由 处理/www/yourproject/public/property/index.php

样本index.php

<?php
var_dump($_GET);

样本输出/property/aid/1234

array(1) {
  ["aid"]=>
  string(4) "1234"
}

例如,您可以用 替换fastcgi_passfastcgi_index指令proxy_pass

于 2016-10-21T02:16:42.853 回答