.htaccess 301 Redirect Folder and Subfolders

I would like to redirect a parent folder to a different place than it’s subfolders. When I use the code below /cat1/page_title redirects to /new-cat-1/page_title, instead of /new-global-cat/page-title.

Redirect 301 /cat1 /new-cat-1
Redirect 301 /cat1/page_title /new-global-cat/page-title
Redirect 301 /cat2 /new-cat-2
Redirect 301 /cat2/page_title /new-global-cat/page-title

It appears the redirect for the parent folder is taking precedence over the redirect for the subfolder. I have a long list of redirects under cat1 and cat2 that I need to redirect.

Read More

How can I have a redirect that works for both the parent and the sub folders without them interfering with each other?

Additional info: This is for a WordPress website.

Related posts

Leave a Reply

1 comment

  1. To fix this problem it is better to use RedirectMatch here for its regex capabilities:

    RedirectMatch 301 ^/cat1/?$ /new-cat-1
    RedirectMatch 301 ^/cat1/page_title/?$ /new-global-cat/page-title
    RedirectMatch 301 ^/cat2/?$ /new-cat-2
    RedirectMatch 301 ^/cat2/page_title/?$ /new-global-cat/page-title