gpt4 book ai didi

apache - 配置 Apache 将 "GET/user/foo"路由到/user/GET.php 并将 "PUT/user/foo"路由到/user/PUT.php

转载 作者:可可西里 更新时间:2023-11-01 17:15:55 30 4
gpt4 key购买 nike

我想安排一些事情,例如 GET 请求

http://example.com/user/foo@bar.com

内部调用脚本

/var/www/example.com/rest/user/GET.php

对同一 URL 的 PUT 请求在内部调用脚本

/var/www/example.com/rest/user/PUT.php

对于其他 HTTP 动词 POST 和 DELETE 依此类推。

这几乎可以通过 <Script> 实现。指令,但它不太有效,因为“Script with a method of GET will only be called if there are query arguments present”。这意味着如果 Apache 是通过

配置的
<Location /user>
Script GET /rest/user/GET.php
Script PUT /rest/user/PUT.php
</Location>

然后,同时一个 GET 请求

http://example.com/user/foo@bar.com?foo=bar

将调用 GET.php ,如果请求不包含查询字符串“foo=bar”,则不会。

(还有,为什么<Script>一开始是这样设计的?)

最佳答案

您可以在 REQUEST_METHOD 上使用 RewriteCond 来使用 mod_rewrite

例如:

RewriteCond %{HTTP_METHOD} ^GET$

关于apache - 配置 Apache 将 "GET/user/foo"路由到/user/GET.php 并将 "PUT/user/foo"路由到/user/PUT.php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1983691/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com