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

标签 apache http rest routing scripting

我想安排一些事情,例如 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/

相关文章:

javascript - WebSocket `closing` 与 `closed` readState 有什么区别?

javascript - 在 JSON 中编码日期的最佳实践是什么?

macos - XAMPP (Mac) 虚拟主机显示 403

php包含模板在ubuntu + apache + php上失败

node.js - HTTP 流和服务器发送的事件有什么区别?

HTTP 作为游戏的通信层

java - RESTful 应用程序编辑未反射(reflect)在 tomcat 上

java - 正则表达式验证未触发 Spring Boot Controller 中的错误

Apache (WAMP) 拒绝 HTTPS 连接

html - 使用 apache 注入(inject) html