Home > Software engineering >  how to replace every directory on my server with index.php
how to replace every directory on my server with index.php

Time:02-28

I'm trying to ensure that every directory on my server redirects users to index.php instead of letting users view my directory as below screenshot

enter image description here

I tried to use .htaccess to do this instead of having to create index.php on every directory but it didn't work, below is what .htaccess looks like:

ErrorDocument 404 "<H1>Page Not Found!</H1>"

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php73” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php73 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
#Alternate default index page
DirectoryIndex index.php

Can anyone help with how to solve this?

CodePudding user response:

So I was able to solve this by just add Options -Indexes on the top of .htaccess below is my update code :


Options -Indexes

ErrorDocument 404 https://websitelink.com/404.php
ErrorDocument 403 https://websitelink.com

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php73” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php73 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
#Alternate default index page
DirectoryIndex index.php
  • Related