How to remove public from url in laravel

浪子不回头ぞ 提交于 2021-02-11 05:54:07

问题


I want ro remove public word from the url in laravel. I tried updating .htaccess and renaming server.php to index.php file but after that I got path error. All the css, js, fonts are not working without public word in the url. Please help me so that I can set all the path of css, js, fonts and remove public word from url in laravel. Any help would be appreciable.


回答1:


Move your all files from /public to your root folder / (which is mainly your laravel folder).

Now open index.php file and edit 2 lines, as below :

require __DIR__.'/../vendor/autoload.php';
// changed to
require __DIR__.'/vendor/autoload.php';

&

$app = require_once __DIR__.'/../bootstrap/app.php';
// changed to
$app = require_once __DIR__.'/bootstrap/app.php';

Now add this lines to your .htaccess to prevent access .env from URL :

<Files .env>
order allow,deny
Deny from all
</Files>

By this method you can host your laravel app in any kind of shared hosting too.

Hope this helps.



来源:https://stackoverflow.com/questions/62128581/how-to-remove-public-from-url-in-laravel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!