Why is my Laravel URL mysite.com/public by default and how do I remove “public” from URL?
Probably the first question most people ask when they install their new Laravel site.
Here are 2 ways, luckily it is easy to do.
1. The most standard one is to just edit .htaccess file and add these lines:
<IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^(.*)$ public/$1 [L] </IfModule>
Note: For this to work you must have mod_rewrite enabled on your Apache server because rewrite module is required to apply these settings.
2. This option is either easier or more complicated, depending on if you can edit ‘Document root’ on your hosting server. So, if you have access to Cpanel of your hosting AND they allow you to change ‘Document root’ then change it from let say “/public_html” to “/public_html/public”. That should do the trick.
If you can’t edit ‘Document root’ by yourself (security measure etc) then the best is to ask your host support to change it to “/public_html/public” (assuming your root folder for website is /public_html . If it is /www then let them change it to /www/public).