如何在 apache php 5.0 中启用 PUT 方法

发布于 2024-12-26 10:44:45 字数 369 浏览 2 评论 0原文

我在 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]

如何添加以启用 PUT 方法? 谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

冷︶言冷语的世界 2025-01-02 10:44:45

这是可能适合您的解决方案

  1. 首先,一个支持 HTTP 摘要身份验证的实用程序文件,该文件
    可以位于目标目录(或常见的 PHP 包含
    目录(如果您可以设置):下载并重命名 dauth.php

  2. 其次,在相关目录中放置以下PHP脚本:
    下载并重命名put.php

  3. 第三,存储以下.htaccess文件在目标目录中,
    将“/path-to-target-directory”替换为域相对路径
    (例如,如果可以在 http://mydomain/x/y/z.html,
    那么 /path-to-target-directory 将是 '/x/y'):
    download并重命名.htaccess

.htaccess 示例:

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]

有关详细信息,请参阅:这里

Here is the solution which may work for you

  1. 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

  2. Second, in the directory concerned, place the following PHP script:
    download and rename put.php

  3. 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

晒暮凉 2025-01-02 10:44:45

约定涉及传输要使用的底层方法(在 POST 请求中)的 X-HTTP-METHOD-OVERRIDE 标头。

您可以在 php 应用程序中获取此请求标头来定义是否处理 PUT 请求。

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.

≈。彩虹 2025-01-02 10:44:45

无需执行任何操作即可使用 apache“启用”PUT 请求。

如果您的意思是您没有收到通过 PUT 请求发送的数据 - 您的代码中需要一些像这样的 php 代码:

 if ($_SERVER['REQUEST_METHOD'] === 'PUT') {
     $data = file_get_contents('php://input');
 }

因为 PUT 请求不会填充 $_POST (显然,因为它不是POST 请求)。

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文