How to redirect a subdirectory and all files to it to the root using htaccess?

I am trying to redirect all requests to a subdirectory and any files in it to the root directory using htaccess. I currently have redirect 301 / directory // But this is redirected to the root with the file name that was added to it .. ie www.domain.com/directory/this.html redirects to www.domain.com/this. html I don’t want it to request a file at all. Is there any way to do this?

thank

Charles

+3
source share
1 answer

You may have to use mod_rewrite. Assuming you put .htaccess in the root directory, something like this should work.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^name-of-subfolder/.*$ / [R=302]
</IfModule>

NB. 302, , 301 . , 302.

+5

Source: https://habr.com/ru/post/1757019/