如何重定向除登录页面之外的子目录


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

我需要将子目录/plays/下的所有WordPress帖子重定向到主目录(/),除了登陆页面。

  • 因此,如果您转到example.com/plays/hello,您将被重定向到example.com/hello
  • 但是,如果您转到example.com/playsexample.com/plays/您将留在该页面上。

我该怎么做?我假设它必须通过.htaccess重定向来完成,但我不知道如何完成。

以下规则应该有效:

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]