简体   繁体   English

Laravel 公共内容无法在共享主机上访问

[英]Laravel public content not a accessible on Shared Host

I'm using a shared hosting with php 7.4 and Laravel.我正在使用带有 php 7.4 和 Laravel 的共享主机。 I created the project inside root www/ folder then I need to add a htaccess file to load index.php我在根 www/ 文件夹中创建了项目然后我需要添加一个 htaccess 文件来加载 index.php

source file: www/.htaccess

<IfModule mod_rewrite.c>
  RewriteEngine On

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

It allowed me to load the website but I couldn't load public content since then.它允许我加载网站,但从那时起我无法加载公共内容。 Runing local server I can load the public resources such as stylesheet运行本地服务器我可以加载样式表等公共资源

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

But on production environment it returns 404 on generated source但是在生产环境中,它在生成的源上返回 404

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

Obviously, the correct URL to the CSS file is http://neovita.web277.uni5.net/public/css/main.css .显然,CSS 文件的正确 URL 是http://neovita.web277.uni5.net/public/css/main.css

If the shared hosting in question allows you to put files & folders at the same level with the www folder, you can make the www folder to be the "public" folder of your Laravel project (by renaming public to www).如果有问题的共享主机允许您将文件和文件夹与 www 文件夹放在同一级别,您可以将 www 文件夹设为 Laravel 项目的“公共”文件夹(通过将 public 重命名为 www)。 Details here: How to change public folder to public_html in laravel 5此处的详细信息: 如何在 Laravel 5 中将公共文件夹更改为 public_html

in .htaccess add this.htaccess添加这个

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM