Only Allow POST Requests and Deny all other REQUEST_METHOD using .htaccess

吃可爱长大的小学妹 提交于 2019-12-11 00:44:33

问题


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?

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

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

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.

can anyone provide some help.


回答1:


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.

You can also do this directly in PHP.



来源:https://stackoverflow.com/questions/12606290/only-allow-post-requests-and-deny-all-other-request-method-using-htaccess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!