403 Forbidden 对该资源的访问在服务器上被拒绝 - Laravel 5.7

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/52351462/
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-09-14 18:03:16  来源:igfitidea点击:

403 Forbidden Access to this resource is denied on server- Laravel 5.7

phplaravel.htaccesslaravel-5.7

提问by Maniruzzaman Akash

I'm working with a project in Laravel 5.7. Everything works in localhost. But, after uploading in the server, all routes for Backend Partis working. But post routes for Frontend Partis not working. It shows the error -

我正在处理一个项目Laravel 5.7。一切都在本地主机上工作。但是,在服务器上传后,所有路由Backend Part都可以正常工作。但是发布路线Frontend Part不起作用。它显示错误 -

403 Forbidden Access to this resource on the server is denied

403 Forbidden 对服务器上此资源的访问被拒绝

.htaccessin root folder is -

.htaccess在根文件夹中是 -

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

Have someone face this problem before? What I've missed. In localhost everything is working fine, but not in Server.

以前有人遇到过这个问题吗?我错过了什么。在 localhost 中一切正常,但在 Server 中则不然。

回答by Gurpal singh

I think you are not generating artisan key. Please run these command on server.

我认为您没有生成工匠密钥。请在服务器上运行这些命令。

composer update
php artisan key:generate

Your htaccess hould be like this

你的 htaccess 应该是这样的

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

RewriteEngine On

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$public / [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

回答by Peyman.H

For handling front end stuffs in /publicadd this to your .htaccess:

为了处理前端的东西,/public将此添加到您的.htaccess

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

回答by Afraz Ahmad

.htaccess looks fine to me Make sure your post routes are being called with form.

.htaccess 对我来说看起来不错 确保你的 post 路由是用表单调用的。

If there is no issue in your backend then

如果您的后端没有问题,那么

You need to grant permissions to server of these directories

您需要向这些目录的服务器授予权限

give permissions to bootstrap/ and storage/ directory as shown below

授予 bootstrap/ 和 storage/ 目录的权限,如下所示

sudo chmod -R 777 storage/ bootstrap/

Then it should work

那么它应该工作