1

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?

  • "parent page" - do you mean "directory"? Is /parent a physical directory on the filesystem? If not, how are these URLs being routed? – MrWhite Sep 29 '17 at 15:17
  • I meant directory (edited now) /parent is both a directory and a page. – Double Clicked Sep 29 '17 at 15:18
1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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