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Ā .htaccess,Ā index.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';
    to
    require DIR.'/bootstrap/autoload.php';
  3. 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>
Was this article helpful to you? Yes No 10

How can we help?