For example this code
class My_Sitemap
{
public static function install()
{
add_filter('rewrite_rules_array', array(__CLASS__, 'rewriteRules'), 1, 1);
global $wp_rewrite;
$wp_rewrite->flush_rules(false);
}
public static function rewriteRules($wpRules)
{
$rules = array(
'sitemap\.xml$' => 'index.php?pagename=my-sitemap',
);
return array_merge($rules, $wpRules);
}
public static function parseRequest($wp)
{
if (!isset($wp->query_vars['pagename'])) {
return true;
}
if ($wp->query_vars['pagename'] !== 'minimal-xml-sitemap') {
return true;
}
self::outputXML();
}
public static function outputXML()
{
echo 'hello';
}
}
register_activation_hook(__FILE__, array('My_Sitemap', 'install'));
add_action('parse_request', array('My_Sitemap', 'parseRequest'));
the rewrite rule is sitemap\.xml$
, shouldn't it be ^sitemap\.xml$
? If I go to mysite.com/asitemap.xml it doesn't work, but mysite.com/sitemap.xml works. Which one is correct?