For the security reasons, Laravel keeps publicly accessible files and index.php in the public directory in root. So the public can not access your core directory structure. You can point your domain to the public directory for accessing directly domain.
But if you want to remove the public from URL badly. you can follow the below steps to get it without making any modification in your domain root path. You can get it in several ways.
- Rename server.php in your Laravel root folder to index.php
- Copy the .htaccess file from the directory
/publicto your Laravel root folder.
Done, try browsing without public in URL, you should go homepage
This is too risky for your application or website because it makes your composer.json, .env and other sensitive files or information publicly accessible via the browser. A good practice is to set your virtual host to /public or point the domain to the public directory. So if you want to go ahead with this instruction, please continue.
index.phpand others directory from the public directory to your root directory. Then change root index.php code as below
- Next after paste, open index.php , modify
$app = require_once DIR.'/../bootstrap/app.php';
$app = require_once DIR.'/bootstrap/app.php';
Now all set, and try to browse your website without public
Don’t forget to prevent
.env file accessing by url
.env from your .htaccess located in the root directory, open it by a text editor and add below code snippet at the end of the page, so your all of credential will be store securely.
<files .env> order allow,deny deny from all </files>