Laravel Remove Public From Url in Shared Hosting

While deploying laravel in shared hosting, we see public at the end of website. That's why it seems bad while visiting website. Laravel mainly starts its execution from public path. After uploading the whole project in public_html or www directory, all folders are are placed inside root directory. Due to missing of index.php inside root directory, site is not visible to public. That's why we need to redirect all requests to public  path after visiting the site example.com.

That's why we need to create a .htaccess file at the root directory. Let's do this 


Read also: Laravel php flash message functionality integration

Read also: Laravel export collection to xlsx file download

Create .htaccess file at root directory of the project and place below 3 lines

Save the file and visit your site now in browser

RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
.htaccess file 


Project file list with .htaccess


After placing, save this file and visit your site https://example.com; Now you are good to go


Read also: Host multiple laravel project on same port in nginx server

Read also: Deploy laravel application using nginx php mysql lemp stack setup in ubuntu

Read also: Laravel model query introduction and usage

Tags: