可选参数的HTACCESS重写?

发布于 2025-02-09 13:35:23 字数 722 浏览 0 评论 0原文

我目前正在尝试实现REST API。为此,应调用的URL应为特定格式:

  1. /customer/{customerId}/
  2. orders/ofers/oferss /customer/{customerId}/orders/oferers/oferes/stries/{ofiends} < /code>

我得到了使用此重写的变体1和2。

RewriteRule ^customer/([a-zA-Z0-9-]+)/orders/periods/([a-z0-9-]+)?$ api/customer.php?customer_id=$1&period=$2 [L]

现在,应选择添加参数“年”:
3。/customer/{customerId}/orders/ofers/ofers?ear = {year}

我的方法是此规则,但这实际上行不通(至少对于变体2)。

RewriteRule ^customer/([a-zA-Z0-9-]+)/orders/periods([a-zA-Z0-9-]+)?$ api/customer.php?customer_id=$1&year=$2 [L]

有人有想法吗?不幸的是,我对重写规则的了解有限。

提前致谢。

I am currently trying to implement a REST API. For this, the URL to be called should be in a specific format:

  1. /customer/{customerid}/orders/periods
  2. /customer/{customerid}/orders/periods/{period}

I got variants 1 and 2 working with this RewriteRule.

RewriteRule ^customer/([a-zA-Z0-9-]+)/orders/periods/([a-z0-9-]+)?$ api/customer.php?customer_id=$1&period=$2 [L]

Now the parameter "year" should be added optionally:
3. /customer/{customerid}/orders/periods?year={year}

My approach would be this rule, but that doesn't really work (at least not for variant 2).

RewriteRule ^customer/([a-zA-Z0-9-]+)/orders/periods([a-zA-Z0-9-]+)?$ api/customer.php?customer_id=$1&year=$2 [L]

Does anyone have any ideas? My knowledge of Rewrite Rules is unfortunately somewhat limited.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文