PUT request 403 Forbidden

前端 未结 3 838
醉话见心
醉话见心 2020-12-19 06:06

Developing an API using laravel.

Getting 403 Forbidden on PUT request.

Works on a remote server but not locally. Using MAMP for the local server.

He

相关标签:
3条回答
  • In my vhosts file I put:

    RewriteCond %{REQUEST_METHOD} !^(HEAD|GET|POST|PUT)$ [NC]
    

    This allowed it for me. I tried all of the other solutions and nothing worked but this.

    0 讨论(0)
  • 2020-12-19 06:47

    According to @drack's answer I edit my .htaccess using this code:

        <Limit GET POST PUT OPTIONS>
            Require all granted
        </Limit>
        <LimitExcept GET POST PUT OPTIONS>
            Require all denied
        </LimitExcept>
    

    My complete .htaccess file is:

    Header add Access-Control-Allow-Origin: "*"
    Header add Access-Control-Allow-Methods: "GET,POST,OPTIONS,DELETE,PUT"
    Header add Access-Control-Allow-Headers: "Content-Type"
    <Limit GET POST PUT OPTIONS>
        Require all granted
    </Limit>
    <LimitExcept GET POST PUT OPTIONS>
        Require all denied
    </LimitExcept>
    # BEGIN WordPress
    RewriteEngine On
    RewriteCond %{REQUEST_METHOD} OPTIONS
    RewriteRule ^(.*)$ $1 [R=200,L]
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    RewriteCond %{HTTP:Authorization} ^(.*)
    RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]
    
    SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
    # END WordPress
    

    And 403 error goes away in put request.

    0 讨论(0)
  • 2020-12-19 06:55

    Found the solution here: https://serverfault.com/questions/275512/put-request-results-in-403-forbidden-need-apache-to-allow-put-requests

    Added the following to .htaccess at the document root:

    <Limit GET POST PUT DELETE HEAD OPTIONS> Order allow,deny Allow from all </Limit> <LimitExcept GET POST PUT DELETE HEAD OPTIONS> Order deny,allow Deny from all </LimitExcept>

    0 讨论(0)
提交回复
热议问题