Laravel 链接 href 无效路径 [英] Laravel link href invalid path
本文介绍了Laravel 链接 href 无效路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 Laravel 中有网站.在 .env
文件中我设置:
I have website in Laravel.
In .env
file I set:
APP_URL=http://localhost:8082/mydomain/public
我在 Windows 上使用 XAMPP.我的 .htaccess
:
I use XAMPP on Windows. My .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>
当我在浏览器中加载主网站时,出现如下错误:
When I load main website in the browser I have errors like that:
http://localhost:8082/js/app.js net::ERR_ABORTED 404 (Not Found)
它不能加载任何 js 或 css 因为正确的路径应该是:
It cannot load any js or css beacuse the correct path should be:
http://localhost:8082/mydomain/public/js/app.js net::ERR_ABORTED 404 (Not Found)
在 php
文件中的链接看起来像:
In file in php
link looks like :
<script src="/js/app.js"></script>
@yield('script')
</body>
</html>
推荐答案
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') }}">
这篇关于Laravel 链接 href 无效路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文