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
?
.png
redirect to:
.php?path=img.png
all other redirects should work like WordPress expects them to.
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
?
https://example.com/subfolder/img.png
redirect to:
https://example.com/subfolder/index.php?path=img.png
all other redirects should work like WordPress expects them to.
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.