Laravel 5 – Remove Public from URL

后端 未结 30 2391
甜味超标
甜味超标 2020-11-22 03:20

I know this is a very popular question but I haven\'t been able to find a working solution for Laravel 5. I\'ve been trying to migrate from Codeigniter for a long time, but

30条回答
  •  梦如初夏
    2020-11-22 03:51

    BEST Approach: I will not recommend removing public, instead on local computer create a virtual host point to public directory and on remote hosting change public to public_html and point your domain to this directory. Reason, your whole laravel code will be secure because its one level down to your public directory :)

    METHOD 1:

    I just rename server.php to index.php and it works

    METHOD 2:

    This work well for all laravel version...

    Here is my Directory Structure,

    /laravel/
    ... app
    ... bootstrap
    ... public
    ... etc
    

    Follow these easy steps

    1. move all files from public directory to root /laravel/
    2. now, no need of public directory, so optionally you can remove it now
    3. now open index.php and make following replacements

    require DIR.'/../bootstrap/autoload.php';

    to

    require DIR.'/bootstrap/autoload.php';

    and

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

    to

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

    1. now open bootstrap/paths.php and change public directory path:

    'public' => DIR.'/../public',

    to

    'public' => DIR.'/..',

    and that's it, now try http:// localhost/laravel/

提交回复
热议问题