【问题标题】:Laravel 5.5 and .htaccess - images and css files are not loadingLaravel 5.5 和 .htaccess - 图像和 css 文件未加载
【发布时间】:2018-12-05 22:08:18
【问题描述】:

我有一个带有Apache2 的全新虚拟服务器。我正在尝试开始我的Laravel 5.5 项目。

它在我的 Homestead 环境中运行良好,但在此服务器上却无法运行。

我正在使用这个 apache 配置:

<VirtualHost *:80>
    ServerName www.myproject.com
    ServerAlias myproject.com new.myproject.com
    ServerAdmin webmaster@myadmin.com
    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>

现在主页已经加载好了,但是如果我点击登录或注册菜单,它会显示一个 Laravel 处理和基于 Blade 模板的页面,但是 CSS、JS 和图像没有加载。文件位于 public/ 文件夹中的位置,它们不是空大小的,并且仍然没有加载。

如果我点击登录页面,登录页面显示的不是这些文件(css、js、图像)...

有人知道吗?

【问题讨论】:

    标签: laravel .htaccess mod-rewrite apache2


    【解决方案1】:

    将 .htaccess 替换为以下内容,并在公用文件夹之外创建 .htaccess 文件。

    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]
    

    【讨论】:

    • RewriteRule ^(login|uploads 为什么登录和上传都在这个列表中?
    猜你喜欢
    • 2019-08-14
    • 1970-01-01
    • 2011-10-22
    • 2012-09-11
    • 1970-01-01
    • 2012-06-19
    • 2017-12-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多