我对拉拉维尔有一点问题。
我的应用程序有一个用户可以上传模板的部分。应用使用此模板创建一个文件夹,用户可以打开此模板的预览。
问题是:
- url localhost/manager/templates/1/打开正确的索引.html但找不到css,js,img,...
这是我的htaccess(在/public中):
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
该文件夹在服务器中是这样的:
-公共
--资产
--经理
---模板
----1
-----索引.html
------.css
-------风格.css
apache 返回 404,在对 htaccess 进行几次更改后,有时我会收到来自 Laravel 的 404。
对不起,我的英语不好。
谢谢
这可能是资产的 url 引用问题。查看拉拉维尔文档:https://laravel.com/docs/5.2/helpers#urls
资产()
使用请求的当前方案(HTTP 或 HTTPS)为资产生成 URL:
$url = asset('img/photo.jpg');
此帮助程序函数将生成所需的完整 URL。
例如,对于指向 css 的链接:
<?php
$url_css = 'css/'; // Into public directory.
?>
<link rel="stylesheet" href="<?php echo $url_css . 'mycss.css';?>">
对于脚本:
<?php
$url_scripts = 'js/'; // Into public directory.
?>
<script type="text/javascript" src="<?php echo $url_scripts . 'myjs.js';?>"></script>
对于图像:
<?php
$url_images = 'img/'; // Into public directory.
?>
<img src="<?php echo $url_images . 'myimage.png';?>" />
您需要将 $url 变量传递给 html(或脚本)文件。