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

0 votes

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?

Nov 12, 2020 in Laravel by kartik
• 37,510 points
5,332 views

1 answer to this question.

0 votes

Hello @kartik,

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

Hope it helps!!

answered Nov 12, 2020 by Niroj
• 82,880 points

Related Questions In Laravel

0 votes
1 answer

How do I write to the console from a Laravel Controller?

Hello @kartik, This can be done with the ...READ MORE

answered Oct 29, 2020 in Laravel by Niroj
• 82,880 points
633 views
0 votes
1 answer

How can I obtain a list of all files in a public folder in laravel?

You could create another disk for Storage ...READ MORE

answered Dec 8, 2020 in Laravel by Niroj
• 82,880 points
3,723 views
0 votes
1 answer

How Can I Remove “public/index.php” in the URL Generated Laravel?

Hello @kartik, If it isn't already there, create ...READ MORE

answered Aug 10, 2020 in Laravel by Niroj
• 82,880 points
13,196 views
0 votes
2 answers

How to delete file from public folder in laravel?

I just want to add @niroj answer  Use ...READ MORE

answered Nov 5, 2020 in Laravel by Helloworld
• 140 points
27,002 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,880 points