How can I change the WordPress root folder .htaccess file to redirect URLs with a specific subfolder to its own index.php and give the path data as a URL variable to the index.php?


redirect to:


all other redirects should work like WordPress expects them to.

  • I assume you mean "rewrite" as opposed to "redirect"? I assume the URL is not meant to change in the browser's address bar.
    – MrWhite
    Commented Dec 8, 2021 at 0:37

1 Answer 1


Try something like the following at the top of the root .htaccess file, before the existing WordPress directives (before the # BEGIN WordPress comment marker):

RewriteCond $2 !^(index\.php)?$
RewriteRule ^(subfolder)/(.+) /$1/index.php?path=$2 [L]

The RewriteCond directive is to ensure that it doesn't try to rewrite requests for index.php itself (or the directory). A request for /subfolder/ only will be served by /subfolder/index.php without the path URL parameter (by mod_dir).

Otherwise, all other requests to that subfolder (whether they map to files, directories or nothing at all) are passed to /subfolder/index.php in the query string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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