Redirect all requests to public folder on Laravel and Lumen using .htaccess

Aug 13 · 1 min read

Recently, I uploaded a Laravel project on the web and I immediately ran into a problem. When I enter the url on a web browser, it shows a list of files of the directory!

After spending some time on Google, I read that the folder structure is actually a security feature of Laravel. The public folder is designed to be the only folder accessible to the public (duh). All other folders (app, database, vendors, etc.) should be inaccessible.

Here’s how I solved this.

I created an .htaccess file on my project’s root folder and added the following code.

After saving the .htaccess file, all requests are now redirected to the project’s public folder.

Let me know through the comments if this helped.

Happy coding!

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade