Setup an .htaccess file for redirecting to Laravel’s public folder

Trung Vu
1 min readMay 7, 2021

In this post, let’s learn how to setup an .htaccess file for redirecting to Laravel’s public folder.

In Laravel the path for serving your web page is in the /public folder. By default after installing Laravel and navigating in a browser to the URL you will see a directory listing of all the Laravel files. Here’s an easy way using an .htaccess file to redirect requests of user to the Laravel /public folder mod_rewrite.

Create a .htaccess file in your root directory and add the following code.

<IfModule mod_rewrite.c>
# That was ONLY to protect you from 500 errors
# if your server did not have mod_rewrite enabled
RewriteEngine On
# RewriteBase /
# NOT needed unless you're using mod_alias to redirect
RewriteCond %{REQUEST_URI} !/public
RewriteRule ^(.*)$ public/$1 [L]
# Direct all requests to /public folder
</IfModule>

I hope it’s helpful for you

--

--