Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

tiago_c's avatar

Can't access assets on public after setting document root to /public

Hi there!

I've just recently started using Laravel on a new project and I hit a problem.

So, I think I've set up everything well for a new project and began working on it. Everything is fine on my local machine (Windows, running WAMP) and I've set it up on a personal VPS (Ubuntu, running NGINX), which is also working fine. Now, my employer is using Shared Hosting and the access is sadly very limited. I have ftp access and he can access some stuff on a cPanel. I've tried deploying to the server directly from my local project with PhpStorm. It seemed ok, only bump was that it was directing to a file listing, but when accessing serverlink/public it seemed ok. I've asked my employer to change the document root to /public and everything went downhill, as I now can't access my assets (css/images) which are on /public. The generated links are what they're supposed to be eg: serverlink/css/mycss.css but the file returns a 404 which is rather odd.

Here's my htaccess:

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

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

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

On my views I'm referencing the assets using blade, like so:

<link href="{{ asset('css/button.css') }}" rel="stylesheet" type="text/css" >

^^ This doesn't show correctly in the forum, I'm using asset('css/something.css') with double curly braces!

What I get when trying to access the files directly in the browser is

"Sorry, the page you are looking for could not be found. 1/1 NotFoundHttpException in RouteCollection.php line 145:"

Can anyone help me out? Going nuts over this, especially as it works fine on my vps! Will I need to forsake Laravel 5 because of the hosting restrictions or can I get around them?

Cheers, Tiago C.

0 likes
2 replies
tiago_c's avatar

Well I did solve it but it was months ago :P Not really sure what made the trick to be honest, but I can tell you that later into development the team decided to go the common route (which I'm sure you've seen suggested) of placing the files in the root directory. Be safe if doing this, as you'll probably want to block access to some sensitive files. If you decide to keep going at, double check your server's configurations and the htaccess, the problem is probably there. Have you tried RewriteBase /public on the htaccess file?

Please or to participate in this conversation.