1. Home
  2. Teachify LMS
  3. Remove Public From URL

Remove Public From URL

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.

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.

  1. Copy .htaccessindex.php and others directory from the public directory to your root directory. Then change root index.php code as below
  2. Next after paste, open index.php , modify

    require DIR.'/…/bootstrap/autoload.php';
    require DIR.'/bootstrap/autoload.php';
  3. 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

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
Was this article helpful to you? Yes No 10

How can we help?