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.
![](https://www.themeqx.com/wp-content/uploads/2020/06/Remove-Public-from-Laravel-URL.png)
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.
Method 1
- Rename server.php in your Laravel root folder to index.php
- Copy the .htaccess file from the directory
/public
to your Laravel root folder.
Done, try browsing without public in URL, you should go homepage
Method 2
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.
- CopyĀ
.htaccess
,Āindex.php
Ā and 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
require DIR.'/ā¦/bootstrap/autoload.php';
torequire DIR.'/bootstrap/autoload.php';
- Modify
$app = require_once DIR.'/../bootstrap/app.php';
to$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
Hide .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>