doujindou4356 2019-06-30 14:50
浏览 174

如何在REST API中更改URI?

I am coding a REST API with php. I want the URI to be .../product/{id} but to get returned a specific "product". -I need to type in ..../product/read_one.php?product_id=7 - read_one is the php file

-I type the URIs in Postman.

How can I change it to .../product/7?

I am confused whether I can even use an .httaccess file or if I have to change up/create a new php file. I haven't found any tips on the internet either.

  • 写回答

1条回答 默认 最新

  • dqkv0603 2019-06-30 15:16
    关注

    You can use .htaccess to do it:

    RewriteEngine On
    RewriteRule ^product/([0-9])+$ ./product/read_one.php?product_id=$1
    

    Basically when a request is made to a url that matches the left side regular expression, it's the same as going to the path on the right.

    This specific regular expression checks for atleast 1 number after product/.

    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?