简体   繁体   中英

Laravel public content not a accessible on Shared Host

I'm using a shared hosting with php 7.4 and Laravel. I created the project inside root www/ folder then I need to add a htaccess file to load 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

<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 .

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). Details here: How to change public folder to public_html in laravel 5

in .htaccess add this

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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