【问题标题】:Installed Laravel 5 in subfolder with modified .htaccess but assets not showing在子文件夹中安装了 Laravel 5,修改了 .htaccess 但资产未显示
【发布时间】:2017-11-10 18:21:50
【问题描述】:

我已将 laravel 5.4 安装在子文件夹中,例如example.com/laravel。

我关注了ka_lin 的anwser,似乎一切正常,除了资产没有显示。但是,如果我将“public”添加到 url,例如 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>

【问题讨论】:

    标签: php laravel .htaccess laravel-5


    【解决方案1】:

    我终于知道为什么了!!

    因为我将我的文件夹命名为“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 配置了解不多,但它对我有用。希望对其他人有所帮助。

    【讨论】:

      猜你喜欢
      • 2017-11-10
      • 1970-01-01
      • 2018-09-22
      • 2015-03-10
      • 1970-01-01
      • 2015-08-08
      • 1970-01-01
      • 2018-02-13
      • 2018-01-14
      相关资源
      最近更新 更多