首页 文章

在Laravel 5中的文件URL中的404

提问于
浏览
0

我对Laravel有点问题 .

我的应用程序有一个用户可以上传模板的部分 . 该应用程序使用此模板创建一个文件夹,用户可以打开此模板的预览 .

问题是:

  • url localhost / manager / templates / 1 /打开正确的index.html但无法找到css,js,img,...

这是我的htaccess(in / 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]

该文件夹在服务器中是这样的:

-上市

--asset

  • 经理

---模板

---- 1

-----的index.html

------ CSS

-------的style.css

apache返回404并且在htaccess中做了几次更改后,有时我从Laravel收到了404 .

抱歉我的英语不好 .

谢谢

1 回答

  • 0

    这可能是您的资产的网址引用问题 . 检查laravel文档:https://laravel.com/docs/5.2/helpers#urls

    asset()使用当前的请求方案(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(或脚本)文件 .

相关问题