How to remove public from URL in Laravel


In this tutorial I will show you how to remove public from URL in laravel. Default laravel access URL is http://example.com/public/. So we need to remove “public” from the URL to get clean urls in Laravel 5.

Remove public from URL in laravel 5 and Lower versions

Move public index.php file to root

It’s a simple method to remove public from URL in laravel below are the steps to do this:

1. Move or Copy public/index.php file to root directory.

2. Now open index.php (on root) and find below code

require __DIR__.'/../bootstrap/autoload.php';
$app = require_once __DIR__.'/../bootstrap/app.php';

change with below code

require __DIR__.'/bootstrap/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';

3. Now you need to use public to use js and css files if these are in public folder like.

<link rel="stylesheet" href="{{ URL::asset('public/css/bootstrap.css') }}">
<script type="text/javascript" src="{{ URL::asset('public/js/jquery.min.js') }}"></script>

Now you have all set you can access URL http://example.com/. Hope this tutorial will help you to remove public from URL in Laravel.

How to remove public from URL in Laravel
How to remove public from URL in Laravel