只允许POST请求和使用的.htaccess拒绝所有其他REQUEST_METHOD [英] Only Allow POST Requests and Deny all other REQUEST_METHOD using .htaccess

查看:991
本文介绍了只允许POST请求和使用的.htaccess拒绝所有其他REQUEST_METHOD的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,我不希望用户来看看用得到一些电子邮件的PHP脚本,但我用它来发送的一封电子邮件,使用Wufoo项目上的webHook如果有人知道它,所以它使用POST,所以我只想允许POST请求,否则,403或404怎么做呢?

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?

我尝试了一些答案在如此发出与浏览Apache Web服务器的文档时,我找到了最好的答案是这样的:

I tried some answers given on SO and browsed documentation of apache web server, the best answer I found was this:

 RewriteEngine On
 RewriteCond %{REQUEST_METHOD} !=GET
 RewriteRule ^.*$ /path/to

不过,我想这应该是写在我的PHP脚本的目录中,我只是想在根目录使用一个的.htaccess。

But I suppose this should be written in the directory where I have PHP Script, I just want use one .htaccess in root.

文件夹结构:

      public_html (would want to use this folders .htaccess only)
      -- email 
         -- mail.php (ONLY POST)

我知道我们可以在 mail.php 使用REQUEST_METHOD直接,但我不想这样做,这是这种事情是不相关的脚本实际上

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.

任何人都可以提供一些帮助。

can anyone provide some help.

推荐答案

这是非常类似的问题:
<一href="http://serverfault.com/questions/270950/only-allow-get-request-with-htaccess">http://serverfault.com/questions/270950/only-allow-get-request-with-htaccess 只要创建适当的.htaccess文件,并把它里面的电子邮件目录。

This is quite similar question :
http://serverfault.com/questions/270950/only-allow-get-request-with-htaccess Just create proper .htaccess file and put it inside "email" directory.

您也可以直接在PHP中做到这一点。

You can also do this directly in PHP.

这篇关于只允许POST请求和使用的.htaccess拒绝所有其他REQUEST_METHOD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆