DEV Community

loading...

Setup An .Htaccess File For Redirecting To Laravel’s Public Folder

TRUNG VU
Full-Stack web developer
・1 min read

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>
Enter fullscreen mode Exit fullscreen mode

I hope it's helpful for you.

Discussion (0)