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

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.

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

Leave a Reply

Your email address will not be published. Required fields are marked *