All beginners have misunderstood the Laravel routing and MVC structure and want to remove public from laravel url. The public clause is there for security purposes.

Whenever you try to run your application using your local server including Xampp or Wamp, you always encounter the public clause in your laravel URL.

Solution #1 – Best Way to Remove Public from Laravel URL

You can map your local IP or local web address to the public directory of Laravel.

  1. First, you need to add a local address to your host file.
  2. If on windows go to C:windows/system32/drivers/etc/hosts edit this file an administrator.
  3. add a new line at the end,             laravel.local
  4. save (as administrator).

Once done, then navigate to your Xampp or Wamp folder

  1. open, httpd-vhosts.conf file from xampp/apache/conf/extra directory
  2. Add the below lines to it and save it.

3. Now restart your Apache server.

Now you can navigate to http://laravel.local in your browser and you won’t see any public clause in your url.

This is the only best way to remove public from laravel url.

Solution #2 On Live server (Shared Hosting or Cloud)

If you are running your Laravel project live on server using Shared Hosting or Cloud then you need to point the domain to public directory.

  1. Open your web hosting WHM, Cpanel or Cloud Account.
  2. Navigate to Add-ons or Domain on WHM and Cpanel or websites on Cloud.
  3. Manage or edit the domain listed for your laravel project.
  4. You may see the pointing directory something like username/public_html/laravel_website_domain/
  5. you need to change and point it to the public directory like this username/public_html/laravel_website_domain/public
  6. cpanel document directory popup
  7. Once it is pointed to the public, you are good to go.


Also, read more about Specific table migration in laravel

Solution #3 Put .htaccess and index file in root (Not Recommended)

  1. Go to Laravel project
  2. navigate to public directory
  3. cut or copy the htaccess file and paste it in the root directory just besides .env and other files.
  4. rename your server.php file to index.php
  5. And you are good to go. (php artisan serve command won’t work anymore)

This is how to remove public from laravel url in the 3 different ways. Let me know in the comment section which one worked for you.
I personally do not recommend the third solution but sometimes it works for many people. It’s not recommended due to a security issue because it will make a loophole to let someone view the env file and you never want this to happen.

Subscribe To Our Newsletter

Subscribe To Our Newsletter

Join our mailing list to receive the latest news and updates from our team.

You have Successfully Subscribed!