[英]Only Allow POST Requests and Deny all other REQUEST_METHOD using .htaccess
I have some email PHP Scripts which I do not want the user to have a look by a GET, but I am using it to send as an email, using wufoo's webHook if anyone knows about it, so it uses POST so I just want POST Requests to be allowed otherwise, 403 or 404 how do I do that? 我有一些电子邮件PHP脚本,我不希望用户通过GET进行查看,但是如果有人知道,我就使用wufoo的webHook将其作为电子邮件发送,因此它使用POST,所以我只想要POST否则,请求将被允许,403或404我该怎么做?
I tried some answers given on SO and browsed documentation of apache web server, the best answer I found was this: 我尝试了SO上给出的一些答案,并浏览了Apache Web服务器的文档,发现的最佳答案是:
RewriteEngine On
RewriteCond %{REQUEST_METHOD} !=GET
RewriteRule ^.*$ /path/to
But I suppose this should be written in the directory where I have PHP Script, I just want use one .htaccess in root. 但是我想这应该写在我有PHP脚本的目录中,我只想在根目录中使用一个.htaccess。
Folder Structure : 资料夹结构:
public_html (would want to use this folders .htaccess only)
-- email
-- mail.php (ONLY POST)
I know we can use REQUEST_METHOD in mail.php
directly but I don't want to do that, it is kind of thing which is not related to the script actually. 我知道我们可以直接在
mail.php
使用REQUEST_METHOD,但是我不想这样做,这实际上与脚本无关。
can anyone provide some help. 谁能提供一些帮助。
This is quite similar question : 这是一个非常类似的问题:
https://serverfault.com/questions/270950/only-allow-get-request-with-htaccess Just create proper .htaccess file and put it inside "email" directory. https://serverfault.com/questions/270950/only-allow-get-request-with-htaccess只需创建适当的.htaccess文件并将其放在“电子邮件”目录中即可。
You can also do this directly in PHP. 您也可以直接在PHP中执行此操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.