Laravel 5 – Remove Public from URL

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

    @rimon.ekjon said:

    Rename the server.php in the your Laravel root folder to index.php and copy the .htaccess file from /public directory to your Laravel root folder. -- Thats it !! :)

    That's working for me. But all resource files in /public directory couldn't find and request urls didn't work, because I used asset() helper.

    I changed /Illuminate/Foundation/helpers.php/asset() function as follows:

    function asset($path, $secure = null)
    {
        return app('url')->asset("public/".$path, $secure);
    }
    

    Now everything works :)

    Thank you @rimon.ekjon and all of you.

    2020 Author's Update

    This answer is not recommended. Instead, handling .htaccess file is recommended.

提交回复
热议问题