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
Laravel 403 Forbidden Error
提问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 .htaccess
file from public folder, and nothing happened.
Any solutions?
我.htaccess
从公共文件夹中删除了文件,什么也没发生。任何解决方案?
回答by Harikrishnan
Your .htaccess
is not parsed by apache because AllowOverride All
directive is missing inside virtualhost configuration. .htaccess
file is required for Laravel. Put back it. Then change apache virtual host configuration on server to allow .htaccess
.
您.htaccess
没有被 apache 解析,因为AllowOverride All
虚拟主机配置中缺少指令。.htaccess
Laravel 需要文件。放回去吧 然后更改服务器上的 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.net
and /var/www/html/example3
with 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!
就如此容易!