How to redirect all requests to your main domain from the /public folder in Laravel?
In this article, you will learn how to redirect all requests from Laravel public folder to your main domain in Apache. Laravel by default redirects every request to the /public folder, so your wesite is accessible at yourdomain.com/public.
After you have installed Laravel in your web root (public_html, web, etc.), look for a .htaccess file in the root directory. Make sure you have enabled the view the hidden files option in your File/FTP manager. If the .htaccess file doesn’t exists, create one.
Open the .htaccess file and add the following code:
1 2 3 4 5 |
RewriteEngine on RewriteCond %{REQUEST_URI} !^public RewriteRule ^(.*)$ public/$1 [L] |
Save the file. After these changes, you and your visitors should be able to access your Laravel website at yourdomain.com.