php Laravel 403 禁止错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43010415/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:44:37  来源:igfitidea点击:

Laravel 403 Forbidden Error

phplaravel.htaccess

提问by Kiddo

As title said, I got error 403 (title of page) on Laravel project. Locally, it's working, but when I'm trying to put it live, on a web-host/my domain it gives me:

正如标题所说,我在 Laravel 项目中收到错误 403(页面标题)。在本地,它正在工作,但是当我尝试将其上线时,在网络主机/我的域上,它给了我:

Forbidden
You don't have permission to access / on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

Forbidden
您无权访问 / 在此服务器上。
此外,在尝试使用 ErrorDocument 处理请求时遇到 404 Not Found 错误。

I deleted .htaccessfile from public folder, and nothing happened. Any solutions?

.htaccess从公共文件夹中删除了文件,什么也没发生。任何解决方案?

回答by Harikrishnan

Your .htaccessis not parsed by apache because AllowOverride Alldirective is missing inside virtualhost configuration. .htaccessfile is required for Laravel. Put back it. Then change apache virtual host configuration on server to allow .htaccess.

.htaccess没有被 apache 解析,因为AllowOverride All虚拟主机配置中缺少指令。.htaccessLaravel 需要文件。放回去吧 然后更改服务器上的 apache 虚拟主机配置以允许.htaccess.

<VirtualHost *:80>
    ServerName www.example.net
    DocumentRoot "/var/www/html/example3"
    <Directory /var/www/html/example3>
         DirectoryIndex index.php
         AllowOverride All
         Require all granted
    </Directory>
</VirtualHost>

Change your virtualhost like this and restart apache by sudo service apache2 restart.

像这样更改您的虚拟主机并通过sudo service apache2 restart.

Replace www.example.netand /var/www/html/example3with correct details.

用正确的细节替换www.example.net/var/www/html/example3

回答by user10774466

If you are using your own Request, change the authorize function to return true:

如果您使用自己的请求,请将授权函数更改为返回 true:

public function authorize()
{
    return true;
}

As simple as that!

就如此容易!