301 redirect all child pages to parent directory using .htaccess

5,652

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 backreference 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.)

Share:
5,652

Related videos on Youtube

Double Clicked
Author by

Double Clicked

At Double Clicked our aim is to make digital marketing simple. For over 10 years we’ve watched the digital marketing industry make itself more and more complicated and to little benefit – this doesn’t have to be the case! We do your marketing. Simple as that. We are Digital Marketing Consultants, based in Brighton.

Updated on September 18, 2022

Comments

  • Double Clicked
    Double Clicked over 1 year

    I need to 301 redirect all child pages of a specific parent directory on my website.

    i.e. redirect www.example/com/parent/child and www.example.com/parent/another-child etc. to www.example.com/parent

    Is this achievable using the .htaccess file?

    • MrWhite
      MrWhite over 6 years
      "parent page" - do you mean "directory"? Is /parent a physical directory on the filesystem? If not, how are these URLs being routed?
    • Double Clicked
      Double Clicked over 6 years
      I meant directory (edited now) /parent is both a directory and a page.