简体   繁体   中英

NGINX - rewrite rules for PHP REST

I am currently learning REST with NGINX (and PHP-FPM).

I have a couple of questions around routing (eg /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?

Second, is rewrite the best way of achieving this, I have seen that you can use alias in NGINX to do something similar?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM