I had reinstalled apache and after I configured it again, my Laravel applications don't work anymore and it shows me the directory structure instead.

- 15,591
- 9
- 34
- 56

- 23
- 7
-
3Does this answer your question? [Apache lists directory files instead of index.php](https://stackoverflow.com/questions/13898386/apache-lists-directory-files-instead-of-index-php) – Nico Haase Dec 22 '20 at 08:43
-
i have already tried that but same result – Karim El Hajjami Dec 22 '20 at 08:50
-
Please share your attempts through editing the question – Nico Haase Dec 22 '20 at 08:53
2 Answers
If you've "reinstalled Apache" then the default DirectoryIndex
is just index.html
. You need this set to index.php
in order to serve your Laravel front-controller.
When Apache does not find the DirectoryIndex
document (eg. index.html
) when requesting a directory and directory indexes/listings (mod_autoindex) are enabled (the default) then Apache generates a directory listing as you are seeing here.
You need to set index.php
as the DirectoryIndex
, for example:
<Directory /var/www/html/wafacashapp>
AllowOverride All
Require all granted
DirectoryIndex index.php
</Directory>
Alternatively, you can set the DirectoryIndex
in your .htaccess
file - if you have one. (If you aren't using .htaccess
files then you should disable .htaccess
overrides by setting AllowOverride None
.)
You should also consider disabling directory indexes/listings, so as to not expose the contents of your directories should a DirectoryIndex
document not be found. For example, in the same <Directory>
container (or .htaccess
file):
Options -Indexes
The user will then be served a 403 Forbidden instead of a directory listing.

- 43,179
- 8
- 60
- 84
you can add .htaccess file to root's of project and add these lines
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

- 145
- 1
- 11
-
I would also disable indexes altogether as a precaution if this is a production environment as you don't want people inadvertently being able to browse directory structure, .htaccess `Options -Indexes`. – Aidan Dec 22 '20 at 09:38
-
1Please add some explanation to your answer such that others can learn from it. Why exactly should that help? What makes you think that the application is structured such that this rule works? – Nico Haase Dec 22 '20 at 09:41
-
laravel index.php is in public directory and maybe there is other's rule to handle it but I fixed this issue by htaccess and these codes – mehri abbasi Dec 22 '20 at 10:05
-
the htacces is located in public folder of the laravel project and i already when i open the application it shows the public directory – Karim El Hajjami Dec 22 '20 at 10:10
-
yes, htaccess is located in public , but url should be like `http://example.com/public` and if user call without public , directories will shown. so we can add htaccess file to root – mehri abbasi Dec 22 '20 at 10:20
-