The default Rank Math sitemap URL is https://example.com/sitemap_index.xml. The rank_math/sitemap/base_url filter adds a folder in front of it, so the index and every child sitemap move to a path like /search-sitemaps/sitemap_index.xml.
You might want this to keep sitemaps out of the site root, to avoid a clash with another tool that expects sitemap_index.xml, or to match the URL structure of a site you migrated to Rank Math.
To control what goes into the sitemap instead, see exclude a post type from the Rank Math sitemap.
The Code
Add the filter to your child theme’s functions.php file or to a custom plugin. This example moves the sitemaps under search-sitemaps/:
/**
* Filter to change the Sitemap URL Base
*
* @param string $base New URL Base
*/
add_filter( 'rank_math/sitemap/base_url', function( $base ){
return 'search-sitemaps/';
}, 10, 1 );
After saving the file, go to Settings > Permalinks and click Save Changes. That flushes the rewrite rules, and until you do it the new URL returns a 404.
How It Works
Rank Math builds every sitemap URL as home_url( $base . $file ). By default $base is an empty string, or index.php/ if your permalink structure includes index.php.
The filter is documented in the Rank Math filters and hooks reference.
Its value is used for the rewrite rules that serve the sitemaps and for the links Rank Math prints: the entries inside the sitemap index, the Sitemap: line in the virtual robots.txt, and the URL shown in the plugin settings.
Two details trip people up:
- Keep the trailing slash. Rank Math appends the file name directly, so
search-sitemapswithout a slash gives yousearch-sitemapssitemap_index.xml. - Don’t add a leading slash. The same string goes into the rewrite rule, and WordPress matches rules against the path without a leading slash, so the sitemap would 404.
How to Find Your Rank Math Sitemap URL
The exact address, including any custom base, is shown at the top of Rank Math SEO > Sitemap Settings > General, next to “Your sitemap index can be found here”. Rank Math also redirects /sitemap.xml to /sitemap_index.xml at the site root.
If your site still uses plain permalinks (?p=123), there are no pretty sitemap URLs. The index is served at ?sitemap=1 instead.
To get the URL in PHP, use Rank Math’s template tag. Rank Math doesn’t register a sitemap object on rank_math(), so rank_math()->sitemap returns null.
if ( function_exists( 'rank_math_get_sitemap_url' ) ) {
$sitemap_url = rank_math_get_sitemap_url(); // Includes the filtered base.
}
After You Change the Base
Moving the sitemap breaks any place that has the old URL stored. Go through this list:
- Submit the new index URL in Google Search Console and remove the old one. Our guide to creating and submitting a sitemap walks through it.
- If robots.txt has a hard-coded
Sitemap:line, update it by hand. Rank Math skips adding its own line when one already exists. - On Nginx, Rank Math shows rewrite rules on the Sitemap Settings screen. They include the base, so copy the updated rules into your server config.
- The built-in
/sitemap.xmlredirect still points to/sitemap_index.xmlat the root, so don’t rely on it once the base changes.
FAQs
Common questions about the Rank Math sitemap URL:
/sitemap_index.xml on your home URL, for example https://example.com/sitemap_index.xml. Each post type and taxonomy gets its own child sitemap, such as post-sitemap.xml and category-sitemap.xml.
rank_math/sitemap/index/slug filter. Return the new name without .xml, then save your permalinks. The base filter changes the folder, the slug filter changes the file name.
<sitemap> entries, such as a sitemap generated by another plugin.