0

I tried to key my site's domain into the google search engine and was shocked to realize that the application folders that shouldn't be public have been indexed. Folders and files are like composer.json, a vendor directory, storage directory, resources directory among others.

How I set up:

The application is in the public_html directory, the index.php is the entry point and is in the root directory(public_html) The other Laravel application directories remain as they are(the default Laravel 7 directory structure)

iDevsKE
  • 75
  • 1
  • 8
  • In the docs there is deployment section that describes minimalistic configurations for apache / nginx. You are asking more for devops stuff rather than laravel itself, but you didnt even mention what is the web server – Bartłomiej Sobieszek Sep 21 '21 at 06:46
  • 1
    "The application is in the public_html folder". Well it should not be in that folder. Your domain should point to the Laravel public folder. The application files should never be in a public folder. – Gert B. Sep 21 '21 at 06:48
  • @BartłomiejSobieszek The web server is apache – iDevsKE Sep 21 '21 at 06:52
  • Does this answer your question? [Stop Google from indexing](https://stackoverflow.com/questions/390368/stop-google-from-indexing) – Nico Haase Sep 21 '21 at 07:08
  • 1
    @NicoHaase it would be better to understand why they are indexed in the first place, because if robots can find them, then everybody can – Anthony Aslangul Sep 21 '21 at 07:14
  • @toyi yes, you are right, but the title of this question is "prevent from being indexed by search engines". If that is the main issue the OP cares about, this is a dupe – Nico Haase Sep 21 '21 at 07:21

2 Answers2

1

The application is in the public_html directory, the index.php is the entry point and is in the root directory(public_html) The other Laravel application directories remain as they are(the default Laravel 7 directory structure)

In a default Laravel installation, there is no index.php in the project directory, only a server.php. If you did any change here, please revert them since it would cause a major security issue.

The only Laravel directory that should be publicly accessible is public.

You are using Apache, it means that the DocumentRoot should be set to /path/to/your/project/public (where public is the Laravel public directory).

This way, every files and directories (app, resources...) above this one will not be accessible.

Anthony Aslangul
  • 3,589
  • 2
  • 20
  • 30
  • Okay, probably I should clarify, the issue is not that the files are accessible. They are not accessible but they have been indexed by search engines. – iDevsKE Sep 21 '21 at 07:08
  • If these files are not accessible, search engines cannot index them – Nico Haase Sep 21 '21 at 07:09
  • 1
    yes @NicoHaase is right, there is no way a search engine can index these files if they are not accessible. I think we all agree that these files cannot be accessible and not accessible at the same time, so can you update your question with both your vhost configuration and your entire project directory structure please? It will help a lot – Anthony Aslangul Sep 21 '21 at 07:12
  • 1
    @iDevsKE That the files are accessible is always an issue. Not only because they get indexed, but also because it's a security risk. So this answer does not only solve the problem in the question, it fixes other problems too. – Gert B. Sep 21 '21 at 07:16
0

you should move all your project files to root then copy your files from public to public_html then point topublic_html in Laravel:

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

public function register()
{
    $this->app->bind('path.public', function() {
        return base_path().'/public_http';
    });
}

Also you can see: How to change public folder to public_html in laravel 5