How to remove public from url in laravel?

Remove public from url laravel :-

Default laravel access url will be :- so if you need to remove “public” in url let’s check how to remove public from url in laravel.

There is two solution to remove public from url:-

1. Using .htaccess :-

Add following code in your .htaccess (if not exist create a .htaccess on laravel root directory)

 2. using content moving :-

it’s a better and simple method to remove public from url below are the steps to do this:-

2.1. Create a folder on root with named “local”(you can give any name).
2.2. Move all files except public folder in the “local” folder.
2.3. Move all the files of public to root directory and remove blank public folder.
so directory structure will be :-
a. local – which have all root files except public folder
b. all files of public folder.

— local
— app
— boostrap
— .gitattributes
— composer.json
— server.php
— and so on —-
— packages
— .htaccess
— favicon.ico
— index.php
— robots.txt

2.4. Now time to change some paths:-
a. open local/bootstrap/paths.php and find below code
‘public’ => __DIR__.’/../public’,
change with below code
‘public’ => __DIR__.’/../../’,
b. open index.php (on root) and find below code
require __DIR__.’/../bootstrap/autoload.php’;
$app = require_once __DIR__.’/../bootstrap/start.php’;

change with below code
require __DIR__.’/local/bootstrap/autoload.php’;
$app = require_once __DIR__.’/local/bootstrap/start.php’;
Now you have all set you can access url if still problem try with clear cache of browser.

Thanks!. If you like this article please dont forget to share and comment