How to redirect to the root directory when accessing a directory

1

Good, I have a problem, I'm making a page and when you enter a directory, load a page which shows all the files or directories contained in the current directory.

How can I redirect the user to the home page and prevent the user from viewing the contents of the directory or entering directories?

    
asked by Asahi Sara 18.08.2016 в 03:16
source

1 answer

1

I will assume that you are using Apache as a web server (taking into account that you use a .htaccess file), this is added to your .htaccess from the public root folder of your website:

# No mostrar listados de directorios
Options -Indexes

# Redirigir al directorio raíz desde /error/
RewriteEngine on
RewriteRule ^error/(.*)$ /$1 [R=301,NC,L]

# También podrías usar
# RedirectMatch 301 ^/error/$ http://www.misitio.com/
    
answered by 18.08.2016 / 03:26
source