How do you redirect all request to public/ folder in laravel 5
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
Introduction
Laravel 5 is an excellent framework for building web applications, and its MVC-based architecture facilitates cleaner code and faster development. However, you might encounter a situation where you have to redirect all requests to your public folder in Laravel 5. This guide will provide a comprehensive solution to this problem while adhering to the best practices.Prerequisites
Before proceeding with the steps, ensure that you have an existing Laravel 5 project and are familiar with the framework fundamentals. You'll need access to your web server or hosting environment and a text editor for making changes to the .htaccess file.Understanding the Public Folder
The public folder is part of the Laravel 5 project structure and contains all the necessary files and directories that facilitate web requests, such as CSS, JavaScript, images, and static content. Redirecting all requests to this directory would ensure a seamless user experience, while still providing access to your application's assets.Implementing the Redirection
There are two approaches you can take to redirect all requests to the public folder: using .htaccess and by modifying your web server's configuration files. We will discuss both methods in detail. 1. Using .htaccess: .htaccess is an Apache configuration file that allows you to tailor its behavior without editing main server configuration files. To redirect all requests to the public folder, simply follow these steps: - Open your Laravel 5 project's root directory (the one containing the public folder) and locate .htaccess. - Inside this file, add the following code:php
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L]php
if (!-e $request_filename) {
rewrite /(.+)$ /public/$1 last;
}php
.htaccess {
Deny from all
Require all denied
}
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L]