How to route to a static folder in Laravel

ChiCgi picture ChiCgi · Mar 23, 2015 · Viewed 35.9k times · Source

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

/public/test

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');
});

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

I can access it this way:

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

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

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

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

Answer

terry low picture terry low · Mar 23, 2015

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