I've searched around and haven't found this specific question asked.

I need to redirect all the 'subfolders' of a directory to the parent directory.

For example, the parent directory is example.tld/directory and all subdirectories such as example.tld/directory/subdirectory-1 and example.tld/directory/subdirectory-2 etc all need to redirect to example.tld/directory

For clarification, these aren't actual directories but Drupal sub-paths, but I believe it should work to do this via htaccess.

Just to make it crystal clear, the URLs




should all redirect to


The idea is to make these subdirectories inaccessible to anyone and be sure that the search engine crawlers do not index these subdirectories.

What would be the proper htaccess code to achieve this?


1 Answer 1


After more searching and digging, I did find that this question had been asked, I just didn't know how to word it!

Here's where I found the answer:

301 redirect all child pages to parent directory using .htaccess

Here is what the answer is - I tested it and it works perfectly:

Near the top of the .htaccess file in the root of your site, you can add the following:

RewriteEngine On
RewriteRule ^(parent/). /$1 [R,L]

The $1 is just a back-reference to parent/ (saves repetition).

Change R to R=301 if this is intended to be permanent. (But only after you have confirmed that it works.)

  • Ha, thought I'd answered something similar before - glad you found it! (Once you have 15+ rep you can also upvote other answers you find useful. ;)
    – MrWhite
    Feb 26, 2019 at 16:45
  • Cool, you've got a great resource here! Feb 27, 2019 at 11:41

Not the answer you're looking for? Browse other questions tagged or ask your own question.