【问题标题】:Configure Apache to route "GET /user/foo" to /user/GET.php and "PUT /user/foo" to /user/PUT.php配置 Apache 以将“GET /user/foo”路由到 /user/GET.php 并将“PUT /user/foo”路由到 /user/PUT.php
【发布时间】:2010-12-31 07:40:32
【问题描述】:

我想安排一些事情,例如 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”,则不包含。

(还有,为什么&lt;Script&gt;一开始是这样设计的?)

【问题讨论】:

    标签: apache http rest routing scripting


    【解决方案1】:

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

    例如:

    RewriteCond %{HTTP_METHOD} ^GET$
    

    【讨论】:

    • 我实际上首先尝试了 mod_rewrite 解决方案,但由于其他原因(ScriptAlias 和/或 FastCGI 驱动的 PHP 出现问题)似乎更难以解决......如果你确实有这个工作,你能发布你的 Apache conf 吗?
    猜你喜欢
    • 2014-07-28
    • 2019-01-16
    • 2017-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-27
    • 2012-07-17
    • 2011-03-31
    相关资源
    最近更新 更多