Laravel 5.5 和 .htaccess - 图像和 css 文件未加载
Laravel 5.5 and .htaccess - images and css files are not loading
我有一个全新的虚拟服务器 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、图像)...
有人知道吗?
用以下内容替换 .htaccess 并在 public 文件夹外创建 .htaccess 文件。
RewriteEngine On
#----------------------------------------------
# | this code use for remove public directory |
#----------------------------------------------
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ / [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// [L,NC]
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
我有一个全新的虚拟服务器 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、图像)...
有人知道吗?
用以下内容替换 .htaccess 并在 public 文件夹外创建 .htaccess 文件。
RewriteEngine On
#----------------------------------------------
# | this code use for remove public directory |
#----------------------------------------------
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ / [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// [L,NC]
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]