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,112 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
559 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,517 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
12,912 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
26,282 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
21,905 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,880 points
2,690 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,880 points
2,560 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,880 points
41,884 views
0 votes
1 answer

How Can I Set the Default Value of a Timestamp Column to the Current Timestamp with Laravel Migrations?

Hello, To create both of the created_at and updated_at columns: $t->timestamp('created_at')->default(DB::raw('CURRENT_TIMESTAMP')); $t->timestamp('updated_at')->default(DB::raw('CURRENT_TIMESTAMP on update ...READ MORE

answered Apr 2, 2020 in Laravel by Niroj
• 82,880 points
11,503 views
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 Aug 11, 2020 in Laravel by Niroj
• 82,880 points
6,946 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP