0

I have installed laravel 5.4 in a subfolder, e.x. example.com/laravel.

I followed ka_lin's anwser and it seems like everything works fine except the assets as they are not showing. However, if I add "public" to the url, like example.com/laravel/public/(asset uri...) I can request the asset. I am wondering if there's anyway to work around with this.

.htaccess which resides in the project root folder:

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

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

   RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(css|js|images)/(.*)$ public/$1/$2 [L,NC]
    RewriteRule ^ index.php [L]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
Joshua Leung
  • 2,219
  • 7
  • 29
  • 52

1 Answers1

0

I finally figured out why!!

Because I named my folder to "img" instead of "images", so I have to change

RewriteRule ^(css|js|images)/(.*)$ public/$1/$2 [L,NC]

to

RewriteRule ^(css|js|img)/(.*)$ public/$1/$2 [L,NC]

And if I have any other assets like fonts, I need to add the folder name to the parentheses and modify

RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]

to include the extension.

I don't know much about apache configuration but it works for me. Hope it help other people.

Joshua Leung
  • 2,219
  • 7
  • 29
  • 52