【问题标题】:"403 Forbidden You don't have permission to access" in the laravellaravel 中的“403 Forbidden You don't have permission to access”
【发布时间】:2021-06-21 14:44:18
【问题描述】:

所有 ajax 请求都因 403 Forbidden 错误而失败。是不是因为htaccess。我在服务器上托管它后遇到了这个问题。我已更改 .htaccess 如下。

<IfModule mod_rewrite.c>
AddHandler application/x-httpd-php72 .php
    RewriteEngine On
    # Removes index.php from ExpressionEngine URLs  
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?url=$1 [PT,L]

</IfModule>

我在 public_html 和根目录的其他文件夹中有公共文件。

我在路径 API\MyContorller 和路径中有文件 Route::apiResources(['post' =&gt; 'API\MyContorller ]);

我遇到了 XHR 请求的问题,即 Ajax Call Put 请求

我正在调用update方法更新vue组件中的表格

 updateQuiz(){
            this.form.put('/api/chapter/'+this.$route.params.id + '/quiz/' + this.form.id);

}

【问题讨论】:

  • 检查this是否有帮助?

标签: laravel .htaccess


【解决方案1】:

记住请求中的 CSRF 令牌。

如果您使用 PUT/DELETE 方法,您可以将其转换为

{
method: 'POST',
data: { _method: 'PUT', _token: token },
}

【讨论】:

    【解决方案2】:

    如果有人遇到这个麻烦。这是将以下代码添加到公共文件夹中的 htaccess 文件的解决方案

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

    【讨论】:

      【解决方案3】:

      如果您使用的主机有网络服务器映射到根目录,您的 htaccess 文件应该包含重定向到 public/index.php 文件的请求 例如

      RewriteEngine on
      RewriteCond %{REQUEST_URI} !^public
      RewriteRule ^(.*)$ public/$1 [L]
      

      【讨论】:

      • 我有 pubiic_html 文件夹而不是 public
      • 我需要在htaccess上添加这个吗
      • 阅读本主题可能对您有所帮助。 stackoverflow.com/questions/50292963/…
      • 在 index.php 文件中需要添加一些更改
      • 显示您如何调用请求。 GET、POST 方法是否存在问题?还是仅使用 PUT/DELETE ?
      【解决方案4】:

      我遇到了类似的问题,原来没有做git init 是这个问题的真正原因。如果您已经将项目挂接到 GitHub 存储库,则无关紧要。确保你在开始时做一个git init,然后在你提交和推送之前做一个git add .

      【讨论】:

        猜你喜欢
        • 2014-03-29
        • 2017-12-25
        • 2011-06-15
        • 2016-04-15
        • 2014-06-04
        • 1970-01-01
        • 2014-05-19
        • 2019-02-20
        • 1970-01-01
        相关资源
        最近更新 更多