我正在Laravel 5.7
的一个项目工作。一切都在localhost中工作。但是,在服务器上传后,Backend Part
的所有路由都正常工作。但是Frontend Part
的发布路线不起作用。它显示错误 -
403 Forbidden拒绝访问服务器上的此资源
根文件夹中的.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>
以前有人遇到过这个问题吗?我错过了什么。在localhost中,一切正常,但在Server中没有。
我认为你不会产生工匠的关键。请在服务器上运行这些命令。
composer update
php artisan key:generate
你的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 /$1 [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}]
为了处理/public
中的前端内容,请将此添加到您的.htaccess
:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
.htaccess看起来很好我确保你的帖子路由是用表格调用的。
如果你的后端没有问题那么
您需要向这些目录的服务器授予权限
授予bootstrap /和storage /目录的权限,如下所示
sudo chmod -R 777 storage/ bootstrap/
然后它应该工作