简体   繁体   中英

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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM