Support » Fixing WordPress » How to rewrite wp-sitemap

  • Hi, my website is infrastructure is quite different and i cannot directly access the sitemap via https://myhosteg.com/wp-sitemap.xml I can only whitelist a url something like this https://myhosteg.com/whitelist/wp-sitemap.xml how can I acheive this? Please advise.

    • This topic was modified 1 year, 7 months ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Developing with WordPress topic
Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    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/

    Thread Starter darylaurito

    (@darylaurito)

    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

    Moderator bcworkz

    (@bcworkz)

    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.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to rewrite wp-sitemap’ is closed to new replies.