Support the ongoing development of →
posted 7 years ago
Last updated 2 years ago.

Although I'm not very experienced in laravel, i know what's probably happening.

When visiting /articles, the css and js files are being served from root "/" directory still, in a relative manner (files are in their correct spot. /css/styles.css, for example).

However, when you go two directories deep in the url structure, the css and js files are being served relative to the current directory, which is now /articles/. Now the Web server is looking for these files in locations such as /articles/css/style.css, which obviously does not exist.

Possible fixes:

  • use base tag in head of document with full root url as href attribute value (not best solution)


<title>app name</title>
<base href="">
  • alternatively, and perhaps better, use base tag with route helper in blade view to fetch root url (still not best solution)

Example :

<title>app name</title>
<base href="{{ route('') }}"

With example of named route of the following in app/Http/routes.php

Route::get('/',  ['uses' => 'IndexController@showIndex',  'as'  => '']);

By using the route helper method above you are affording yourself being untied to your current routes and url structure. You could change the / to /newindex in routes and the base href in this template would remain the same provided the route name stays the same too.

  • setting rewritebase in Apache .htaccess (or similar server config file) - (it'll work, but still not best)
RewriteEngine On
RewriteBase /
  • use full url with domain name in link and script tags (still not best)
<script src="">

And, finally :

  • use URL::asset() (this is the best solution)
<script src="{{ URL::asset('css/styles.css") }}
Last updated 7 years ago.

Sign in to participate in this thread!


Your banner here too?


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 - All rights reserved.