To have WP recognize /whitelist/ sitemap requests, it’s a matter of using add_rewrite_rule()
to include whitelist/ in the matching regex. In fact, your existing whitelist scheme might already more or less do the same thing. I don’t know how your whitelist scheme works, I’m only speculating.
The problem is more in having the robots.txt entry and all the sub-sitemap URLs listed in the sitemap index to all include /whitelist/ in their URLs. Altering what the various sitemap provider classes do gets pretty messy real quick, and there are not a lot of filter opportunities we can use.
However, I think you can leverage the “home_url” filter to add /whitelist/ to all paths that involve any of the sitemap URLs.
https://developer.wordpress.org/reference/hooks/home_url/
Hi, thanks for the reply. Can I use htaccess to set the rewrite rule, for eg.
RewriteRule ^wp-sitemap\.xml$ /subdirectory/wp-sitemap.php [L]
Kindly advise. Thanks
Would not hurt anything to give it a try 🙂 But you’ll also need to revise the match regex to match any of the sub-sitemaps, capturing the filename for use in the redirect path. But see if what you have works for the one file before fussing with a more powerful rewrite rule.
Check with your browser’s network developer tool if adding such a rule results in a 300 series status being returned. Search bots may not be happy with a 300 series status. If so, you should still consider getting WP to output the proper URLs to start with, using the “home_url” filter.