问题
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