[英]NGINX - rewrite rules for PHP REST
I am currently learning REST with NGINX (and PHP-FPM). 我目前正在使用NGINX(和PHP-FPM)学习REST。
I have a couple of questions around routing (eg /customers). 关于路由,我有几个问题(例如/ customers)。
First of all should I be using NGINX or PHP for routing (put them as rewrite rules like /customer/{cusID}
would map to /customer.php?cusid={cusid})
or rewrite based on /customer/{cusID}
mapping to /customer.php
and then deal with if it has a cusID
resource in the URI using PHP? 首先,我应该使用NGINX或PHP进行路由(将它们作为重写规则,例如
/customer/{cusID}
映射到/customer.php?cusid={cusid})
还是基于/customer/{cusID}
映射进行重写/customer.php
,然后使用PHP处理URI中是否有cusID
资源?
Second, is rewrite the best way of achieving this, I have seen that you can use alias in NGINX to do something similar? 其次,重写是实现此目标的最佳方法,我已经看到您可以在NGINX中使用别名来执行类似的操作?
In this case I would use a simple rewrite rule as follows: 在这种情况下,我将使用以下简单的重写规则:
rewrite ^customer/([0-9]+)$ /customer.php?cusid=$1 last
Your URL will be kept pretty-printed and you will be able to deal with the specified customer id within your PHP code. 您的URL将被打印精美,您将能够在PHP代码中处理指定的客户ID。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.