Posted  by 

Laravel Remove Public From Url

In this post, I will tell you how to remove public from URL in Laravel. Such as Suppose your URL is http://localhost/yourproject/public But you don’t want to write each time public to access a URL That’s mean you want your URL like http://localhost/yourproject/ .Although you can also remove public while deploying your project in your live host. But I will show you how you can remove public from Laravel URL in localhost. Following the steps of how to do that.

Steps of removing Public from Laravel URL

Laravel Url Helper

Remove public from URL -Laravel 5+ Method 1. Copy the.htaccess file from the directory /public to your Laravel root folder. Another Method 2 (Risky). This is too much risky for your application or website, because of it makes your composer. Don’t forget to prevent.env file accessing by url. Today, we will explain you how to remove public from url in laravel. When run application that time we face that problem. But today, we will share some solution of laravel how to remove public from url and remove public directory in laravel. There are two ways remove public from url in laravel. (1) Rename File and move htaccess file (2)create htaccess File.

  1. Go to mainproject/public

a. .htacess

b. favicon.ico

Laravel Remove Public From Url

c. index.php

d. robots.txt

e. web.config

Remove
  1. Cut these Above 5 files from the public folder, and then paste on the main project folder that means outside of public folder.mainproject/files
  2. Next after paste, open index.php , modify

to

5.7
  1. Modify
$app=require_once __DIR__.'/./bootstrap/app.php';

to

Youtube link: https://youtu.be/GboCYqEbKN0

Saint seiya omega dub. For Video

Share with:


For the security reasons, Laravel keeps public accessible files and index.php in the public directory in root. So the public can not access your core directory structure. You can point your domain to the public directory for accessing directly domain.

But if you want to remove public from URL badly. you can follow the below steps to get it without making any modification in your domain root path. You can get it by the sevaral way.

Method 1

  • Rename server.php in your Laravel root folder to index.php
  • Copy the .htaccess file from the directory /public to your Laravel root folder.

Done, try browsing without public in URL, you should go homepage

Another Method 2 (Risky)

This is too much risky for your application or website, because of it makes your composer.json, .env and others sensitive files or information publicly accessible via the browser. Good practice is to set your virtual host to /public or point domain to the public directory. So if you want to go ahead with this instruction, please continue.

Copy .htaccess, index.php and others directory from the public folder to root directory. Then change root index.php code as below

Laravel 6 Remove Public From Url

Now all set, and try to browse your website without public

Laravel 5.7 Remove Public From Url

Laravel Remove Public From Url

Don’t forget to prevent .env file accessing by url

Laravel 8 Remove Public From Url

Hide .env from your .htaccess located in the root directory, open it by a text editor and add below code snippet at the end of the page, so your all of credential will be store securely.