簡體   English   中英

有沒有一種方法可以根據http請求的獲取還是發布來重定向它?

[英]Is there a way redirect http requests based on whether its get or post?

我想擁有一個諸如mysite.com/CustomerIds之類的API,並且能夠通過.httpaccess文件將GET和POST請求重定向到不同的php文件。 例如。 GET將轉到CustomerIds_get.php,而POST將重定向到CustomerIds_post.php。

.httpaccess是特定.httpaccess Web服務器的,它不是PHP的一部分。 但是,用PHP進行操作就足夠簡單了,它的額外好處是將您的代碼全部放在一個地方,而不是依賴於Web服務器配置。

CustomerIds.php

<?php
if ($_SERVER['REQUEST_METHOD'] == "POST")
{
    include("CustomerIds_post.php");
}
else
{
    include("CustomerIds_get.php");
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM