How enable PUT method in apache php 5.0
Question
I have a content in htaccess
Options FollowSymLinks
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule .* index.php
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
How do I add to enable PUT method? Thanks
Solution
Here is the solution which may work for you
First, a utility file to support HTTP digest authentication, which can be located in the target directory (or a common PHP include directory if you can set one up): dowload and rename dauth.php
Second, in the directory concerned, place the following PHP script: download and rename put.php
Third, store the following .htaccess file in the target directory, replacing '/path-to-target-directory' with the domain-relative path (e.g. if a target file can be read at http://mydomain/x/y/z.html, then the /path-to-target-directory would be '/x/y'): download and rename .htaccess
.htaccess
example:
Options FollowSymLinks
RewriteEngine on
RewriteBase /path-to-target-directory
RewriteCond %{REQUEST_METHOD} !PUT
RewriteRule ^/put\.php$ - [F]
RewriteCond %{REQUEST_METHOD} PUT
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^/put\.php$ - [F]
RewriteCond %{REQUEST_METHOD} PUT
RewriteRule ^(.*)$ put.php?url=$1 [L]
For more info refer: Here
OTHER TIPS
Conventions talk about the X-HTTP-METHOD-OVERRIDE
header that transports the underlying method to be used (in a POST request).
You can get this request header in your php application to define whether or not you handle a PUT request.
No action is required to "enable" PUT requests with apache.
if you mean that you don't receive the data sent with a PUT request - you need some php code like this in your code:
if ($_SERVER['REQUEST_METHOD'] === 'PUT') {
$data = file_get_contents('php://input');
}
since a PUT request will not populate $_POST
(obviously, since it's not a POST request).