【问题标题】:Laravel link href invalid pathLaravel链接href无效路径
【发布时间】:2021-02-08 15:22:04
【问题描述】:

我在 Laravel 有网站。 在我设置的.env 文件中:

APP_URL=http://localhost:8082/mydomain/public

我在 Windows 上使用 XAMPP。我的.htaccess

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    RewriteCond %{REQUEST_URI} !^/public/
    RewriteRule ^(.*)$ public/$1 [L,QSA]
</IfModule>

当我在浏览器中加载主网站时,出现如下错误:

 http://localhost:8082/js/app.js net::ERR_ABORTED 404 (Not Found)

它无法加载任何 js 或 css,因为正确的路径应该是:

 http://localhost:8082/mydomain/public/js/app.js net::ERR_ABORTED 404 (Not Found)

php 文件中的链接看起来像:

<script src="/js/app.js"></script>
@yield('script')
</body>
</html>

【问题讨论】:

  • 您在项目的根目录中引用了.htaccess 文件吗?尝试将您的 APP_URL 设置为 http://localhost:8082

标签: css laravel url-rewriting


【解决方案1】:
try this code put it in your app/Helpers/helper.php

function asset($path, $secure = null){
    return app('url')->asset("public/" . $path, $secure);
}

and access resource like eg

 <link rel="stylesheet" type="text/css" href="{{ asset('FOLDER_NAME/css/FILENAEM_EXTENSION') }}">

【讨论】:

    猜你喜欢
    • 2018-09-18
    • 2014-06-10
    • 1970-01-01
    • 2015-09-18
    • 1970-01-01
    • 2016-12-18
    • 1970-01-01
    • 2018-11-01
    • 2019-08-10
    相关资源
    最近更新 更多