jmarrdiaz
11/28/2016 - 10:18 AM

Make Laravel(4) work without `public/` in the URL

Make Laravel(4) work without public/ in the URL

Make Laravel(4) work without `public/` in the URL

PHP LARAVEL
There is a huge security risk involved if you don't hide your app and other directories via .htaccess. Even then the files in the root directory wil be accessible via the browser. Use this method only if you can hide all important files on the browser.
I saw a lot of tricks to modify the .htaccess or to place the other directories outside the root and to simply point the vhost configuration of your apache web server to point to the public directory. None of these make sense when you are developing on an ubuntu box and want to replicate a production environment.

A little bit of snooping around the code will help you competely remove public from the URL. If you have a git repository around the project, you can put this commit in a different branch and cherry-pick it just in case you want to roll back for a future version.

The steps are simple:

Move the contents of the public directory into your application directory.
Modify the public value in bootstrap/paths.php return value to 'public' => __DIR__.'/../../<application-folder>',
Modify the paths in the index.php file that you just moved from the public folder to :
// require __DIR__.'/../bootstrap/autoload.php';
require __DIR__.'/bootstrap/autoload.php';

// $app = require_once __DIR__.'/../bootstrap/start.php';
$app = require_once __DIR__.'/bootstrap/start.php';