I have the following code in my .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
# block text, html and php files in the folder from being accessed directly
RewriteRule ^content/(.*)\.(txt|html|php)$ error [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
# Prevent file browsing
Options -Indexes
To block accessing txt, html, php files in the content folder. It works great and it blocks index.html if access the following URI
mysite.com/content/index.html
but it's not blocking the index.html content being displayed if it's omitted from URI like:
mysite.com/content/
How to solve this problem? Thank you.
You can define a variable like window. parentPage = true; in the index. html file.
By default, PHP does not restrict which files and directories your PHP scripts can access. To restrict the directories that can be accessed, you can use PHP's open_basedir setting.
You need to disable the directory index, not blocking anything. Just add this to your .htaccess file:
DirectoryIndex none.none
Options -Indexes
First line is to tell apache not to serve the "index.html" in case of a user navigates to the folder. More info at DirectoryIndex doc.
Second is to tell apache not to show the content of the folder, because there is no default file to show (First line disable it)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With