.htaccess todavía permite el acceso a archivos
Si quiero evitar que un usuario aleatorio use la URL para buscar un archivo web, necesito usar un archivo .htaccess.
He agregado mi código a continuación. Creé un archivo .htaccess y lo coloqué dentro de mi carpeta de inclusión para evitar que los usuarios naveguen y lean mi archivo database.php.
Siguiendo las instrucciones que se encuentran aquí: https://www.plothost.com/kb/how-to-deny-access-to-a-specific-file-on-your-site-via-htaccess/
Por supuesto que hice algunas pequeñas modificaciones.
Aquí está el código en mi archivo .htaccess:
<files database.php>
Order Allow,Deny
Deny from all
</files>
Usando lo anterior, todavía puedo URL directamente al archivo database.php. Necesito evitar que esto suceda.
¿Qué estoy haciendo mal?
Respuestas
Por favor revisa lo siguiente:
- Asegúrese de que su archivo .htaccess se llame realmente ".htaccess"
- El archivo .htaccess debe estar en el directorio correcto
o la ruta del archivo debe ser relativa al archivo .htaccess.
Acabo de ejecutar esto en mi máquina. El mismo código que ha utilizado. Mi estructura:
Los archivos son idénticos. Comenté el contenido del archivo .htaccess en el directorio raíz. Entonces ahora puedo llamar localhost:8080/database.php
pero no localhost:8080/test/database.php
=> obtengo un Error 403
(acceso denegado).
EDITAR
¿Qué tal esta guía aquí? configurar htaccess
Parece legitimo. Esta es mi configuración. Según la guía, solo se trata de configurar este archivo de configuración y reiniciar.
EDITAR 2
Descubrí que el httpd.conf que había abierto no es el correcto. Encontré el correcto en:Application/XAMPP/xamppfiles/etc/httpd.conf.
En este archivo tienes que buscar:
#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs"
<Directory "/Applications/XAMPP/xamppfiles/htdocs">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/trunk/mod/core.html#options
# for more information.
#
#Options Indexes FollowSymLinks
# XAMPP
Options Indexes FollowSymLinks ExecCGI Includes
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
#AllowOverride None
# since XAMPP 1.4:
AllowOverride All
#
# Controls who can get stuff from this server.
#
Require all granted
</Directory>
Aquí encuentras esto:
#AllowOverride None # this does deactivate .htaccess
# since XAMPP 1.4:
AllowOverride All # this does activate .htaccess
Al menos para mí, esto fue el único responsable de la reescritura de .htaccess. Cuando lo configuro en AllowOverride None, el .htaccess se ignora por completo.
Puede hacer esto usando una mod_rewrite
regla en la raíz del sitio .htaccess:
RewriteEngine On
RewriteCond %{THE_REQUEST} /database\.php[?\s/] [NC]
RewriteRule ^ - [F]