簡體   English   中英

在修改了.htaccess的子文件夾中安裝了Laravel 5,但資產未顯示

[英]Installed Laravel 5 in subfolder with modified .htaccess but assets not showing

我已經在子文件夾(例如example.com/laravel)中安裝了laravel 5.4。

我跟隨了ka_lin的答案,似乎一切正常,除了資產沒有顯示出來以外。 但是,如果我在網址中添加“ public”,例如example.com/laravel/public/(asset uri ...),則可以請求資產。 我想知道是否有任何解決方法。

.htaccess位於項目根文件夾中:

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

我終於明白了為什么!

因為我將文件夾命名為“ img”而不是“ images”,所以我必須進行更改

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

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

如果我還有字體等其他資產,則需要將文件夾名稱添加到括號中並進行修改

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

包括擴展名。

我對apache配置了解不多,但是對我有用。 希望它對其他人有幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM