How to redirect a sub directory except for the landing page?

I need to redirect all my WordPress posts under the sub-directory /plays/ to the home directory (/) except for the landing page.

  • So if you go to example.com/plays/hello you will be redirected to example.com/hello
  • But if you go to example.com/plays or example.com/plays/ you will stay on that page.

How can I do this? I’m assuming it has to be done through a redirect via .htaccess but I don’t know how.

Related posts

1 comment

  1. The following rule should work :

    RewriteEngine on
    
    #if the request is for "/plays" or "/plays/", skip the rule#
    RewriteCond %{REQUEST_URI} !^/plays/?$
    #otherwise redirect to homepage#
    RewriteRule ^plays/(.+)$ http://domain.com/$1 [R,L]
    

Comments are closed.