I feel like I’ve tried everything to get this to work, but my currently-limited knowledge of wordpress may be responsible.
I want to modify part of a query string in a url, so
/my_site/wp-admin/admin.php?page=events
will redirect to:
/my_site/wp-admin/admin.php?page=espresso_events
These urls are hard-coded within the plugin, but I want to be able to define my own query string that will point to the url, adding any additional query parameters onto the end.
function plugin_activate()
{
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
function remove_espresso_url()
{
add_rewrite_rule('page=events&(.*)$',
'wp-admin/admin.php?page=espresso_events&$matches[1]',
'top'
);
}
register_activation_hook(__FILE__, 'plugin_activate');
add_action('init', 'remove_espresso_url');
The rule is appearing in $wp_rewrite->non_wp_rules
. I’ve tried various rule variations, and even entirely different rules, but nothing works. I’ve checked my local server settings and url rewriting is enabled, and my .htaccess file is fine as well.
I’ve also installed the Monkeyman Rewrite Analyzer plugin, and my rewrite rules aren’t appearing in there at all.
Here’s the resulting value from wp_rewrite->mod_rewrite_rules()
RewriteEngine On
RewriteBase /event_espresso/
RewriteRule ^index.php$ - [L]
RewriteRule ^page=events&(.*)$ /event_espresso/wp-admin/admin.php?page=espresso_events&$matches[1] [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /event_espresso/index.php [L]
Edit: This appears to be because I’m trying to rewrite the query string, however what I need to do is use RewriteCond %{QUERY_STRING}
, but I’m not sure WordPress allows me to add new rewrite conditions.
I finally resolved the problem.
For the sake of brevity, I’ll just link to my new question, where I’ve posted the answer; Custom .htaccess rewrite rules in wordpress not executing