Easy way to remove “/public” in the URL path in Laravel 5.2

How to remove the /public path from your URL in Laravel 5.2 the easiest way if you can’t or don’t want to modify the Apache document root ?

In a fresh Laravel 5.2 install, the public frontend is located in

 example.com/public/index.php

To remove the /public/ part of your URL, simply copy-paste /public/index.php and /public/.htaccess to /index.php and /.htaccess.

cd your/project/folder
cp public/index.php index.php
cp public/.htaccess .htaccess

And of course, modify the path within index.php :

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

becoming :

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

This is by far not the best way to do it but the easiest way if you can’t modify your Apache configuration files for examples.

A better way to do it if you have to push it to a production server would be to move all your Laravel files from the project root folder in another place in your server and keep the content of the /public folder in your server root url.

Then, just update the index.php consequently.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: