Ad

Laravel 5.5 And .htaccess - Images And Css Files Are Not Loading

I have a brand new virtual server with Apache2. I'm trying to start my Laravel 5.5 project.

It's working fine in my Homestead enviroment, but on this server it isn't work.

I'm using this apache config:

<VirtualHost *:80>
    ServerName www.myproject.com
    ServerAlias myproject.com new.myproject.com
    ServerAdmin [email protected]
    DocumentRoot /var/www/www.myproject.com/current/public
    CustomLog /var/www/www.myproject.com/log/access.log vhost_combined
    ErrorLog /var/www/www.myproject.com/log/error.log
    RewriteEngine On
    LogLevel alert rewrite:trace3
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ /var/www/www.myproject.com/current/public/index.php [L]
    <Directory />
        AllowOverride None
        Order Deny,Allow
        Deny from all
    </Directory>
    <Directory /var/www/www.myproject.com/current/public>
        Options FollowSymLinks MultiViews
        Require all granted
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

Now the main page is loaded well, but if I click on Login or Register menu, witch are a Laravel handled and Blade template based pages it's showed, but the CSS, JS and images are not loading. Files are sitting on their place in public/ folder, they are not null-sized, and still not loading.

If I click on login page, instead of these files (css, js, images) the login pages showed...

Has anybody any idea?

Ad

Answer

Replace .htaccess with following and create .htaccess file outside public folder.

RewriteEngine On


#----------------------------------------------
# | this code use for remove public directory |
#----------------------------------------------




RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteCond %{REQUEST_URI} !(\.ico|\.css|\.js|\.png|\.jpg|\.gif|robots\.txt|\.eot|\.svg|\.ttf|\.woff|\.woff2|\.otf|\.pdf)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(login|uploads|assets|css|js|images|ca|favicons|fonts|)/(.*)$ public/$1/$2 [L,NC]


RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
Ad
source: stackoverflow.com
Ad