301 redirect all child pages to parent directory using .htaccess
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.)
Related videos on Youtube
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, 2022Comments
-
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
andwww.example.com/parent/another-child
etc. towww.example.com/parent
Is this achievable using the .htaccess file?
-
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 over 6 yearsI meant directory (edited now) /parent is both a directory and a page.
-