Laravel 5 – Remove Public from URL

后端 未结 30 2389
甜味超标
甜味超标 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:38

    DON'T!

    YOU REALLY SHOULD NOT rename server.php in your Laravel root folder to index.php and copy the .htaccess file from the /public directory to your Laravel root folder!!!

    This way everyone can access some of your files (.env for example). Try it yourself. You don't want that!


    DO

    Instead, you should create an .htaccess file in your root like this:

    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/public/
    RewriteRule ^(.*)$ /public/$1 [L,QSA]
    

    This will silently rewrite all your base URIs to the /public folder. Even all Headers, for example the HTTP Authorization Header, and all optional URI parameters will silently be passed on to the /public folder as well.

    That's all

    Please note when setting up a Laravel project with Docker: you won't need to do any of this.

提交回复
热议问题