You can create a new rewrite rule in Wordpress something like this:
function sitemap_rewrite($wp_rewrite) {
$rules = array('sitemap' => 'index.php?action=sitemap');
$wp_rewrite->rules = $rules + $wp_rewrite->rules;
return $wp_rewrite;
}
add_action('generate_rewrite_rules', 'sitemap_rewrite');
function flush_rewrite_rules() {
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
add_filter('init', 'flush_rewrite_rules');
You should only need to run these functions once (when your theme is installed for example) because the rewrite rules are stored in the database.
However, you'll probably find that using this method you cannot access your action
variable using $_REQUEST['action']
. To access your variable you'll have add it to Wordpress' query_vars
array, something like this:
function add_action_query_var($vars) {
array_push($vars, 'action');
return $vars;
}
add_filter('query_vars', 'add_action_query_var');
You can then retrieve the action variable using get_query_var('action')
.