How to redirect your Laravel website from the /public folder to the main domain

In this article, you will learn how to make your Laravel public folder open directly when you type your domain.

If you have installed Laravel on your primary domain for the account in your public_html folder (root directory for the primary domain), but you do not want your visitors to see the default domain.com/public url, follow these steps:

Look for .htaccess files in your public_html (or your domain root folder). By default, dotfiles are hidden in your File Manager. To view all dotfiles, including .htaccess, follow these steps. If you still cannot find the .htaccess file, create a New File from File Manager, named .htaccess.

cPanel Hosting from WebhostFace

After you open the .htaccess file, add the following code:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

Click to save your changes.  After this, you and your visitors should be able to access your Laravel public folder via domain.com. Keep in mind that you might have to clear your browser cache

Get a new cheap cPanel hosting account or test your developer`s skills on our Laravel Hosting packages. Now with 40% OFF the regular price – starting from only $2.94/month!

In case you wish to install Laravel in a folder different than your public_html (for example if you already have a different site on your primary domain name), we strongly advise that you create a subdomain for it (for instance laravel.domain.com). After you install Laravel on the newly created subdomain, you can follow the steps above. This is also valid if you have installed Laravel on an addon domain under your account.