如何在Laravel中路由到静态文件夹

如何在Laravel中路由到静态文件夹

本文介绍了如何在Laravel中路由到静态文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Laravel网站的/public文件夹中有一个文件夹.路径是:

I have a folder I've placed in the /public folder in my Laravel site. The path is:

/public/test

"test"文件夹中有一个名为index.html的文件,这只是我要从公共文件夹中加载的静态资源(我不想在框架内为此创建视图,太多了以至于无法解释).

the "test" folder has a file called index.html that is just a static resource I want to load from the public folder (I don't want to create a view for this within the framework--too much to explain).

我已经做了一条这样的路线:

I've made a route like this:

Route::get('/test', function() {
  return File::get(public_path() . '/test/index.html');
});

我无法使它正常工作.我只是从Chrome收到一个错误,说此页面具有重定向循环.

I'm not able to get this to work. I just get an error from Chrome saying this page has a redirect loop.

我可以这样访问它:

http://www.example.com/test/index.html

但是我不能在任何地方使用.html扩展名.该文件必须显示为:

But I can't use the .html extension anywhere. The file must be visible as:

http://www.example.com/test/

如何在不使用.html扩展名的情况下从Laravel公共文件夹提供单个HTML页面?

How can I serve a single HTML page from the Laravel public folder without having to use the .html extension?

推荐答案

以前曾面对此问题,这是一个肮脏的小技巧,您可以将测试文件夹重命名为其他名称然后进行更新

used to face this problem before, as a dirty little trick, you may rename the test folder to something else then update

return File::get(public_path() . '/to new folder name/index.html');

关键是您的路线网址与您在公共场所的文件夹之间没有冲突

the key is no conflict between your route url with your folder in public

这篇关于如何在Laravel中路由到静态文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 13:23