首页 > 解决方案 > Laravel 公共内容无法在共享主机上访问

问题描述

我正在使用带有 php 7.4 和 Laravel 的共享主机。我在根 www/ 文件夹中创建了项目,然后我需要添加一个 htaccess 文件来加载 index.php

source file: www/.htaccess

<IfModule mod_rewrite.c>
  RewriteEngine On

  RewriteRule ^ /public/index.php [L]
</IfModule>

它允许我加载网站,但从那时起我无法加载公共内容。运行本地服务器我可以加载样式表等公共资源

<link rel="stylesheet" href="{{ URL::asset('css/main.css')}}">

但在生产环境中,它在生成的源上返回 404

<link rel="stylesheet" href="http://neovita.web277.uni5.net/css/main.css">

标签: phplaravelmod-rewrite

解决方案


.htaccess添加这个

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

推荐阅读