Custom .htaccess rewrite rules in wordpress not ex

2019-09-11 01:43发布

问题:

Issue:

I'd like to be able to modify a url query string parameter for a plugin in wordpress, and take the original url;

/wp-admin/admin.php?page=espresso_events

and be able to access it via;

/wp-admin/admin.php?page=events

As far as I can tell everything in my .htaccess file is correct, but for some reason it still doesn't work. The rules however look fine, so I cannot understand why wordpress is throwing me an error when I try to access the page via the new url.

This is my .htaccess file;

RewriteEngine On
RewriteBase /event_espresso/
RewriteRule ^index\.php$ - [L]
RewriteCond %{QUERY_STRING} ^(.*)events(.*)$
RewriteRule . wp-admin/admin.php?%1espresso_events%2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /event_espresso/index.php [L]

Using this online tool, it gives me the correct output url, but when I try the input url directly in wordpress, I just get the same error each time;

You do not have sufficient permissions to access this page.

Edit:

This is definitely a wordpress issue. When I manually update my .htaccess file, everything works correctly, however, when using the mod_rewrite_rules filter, wordpress doesn't appear to be writing the rule to my .htaccess file, or executing them. I have full write permissions on my .htaccess file.

回答1:

This issue has been resolved now. I wasn't flushing the rewrite rules properly via my plugin, so my rewrite rules weren't even being added to the .htaccess file.

function plugin_activate()
{
    //make sure rewrite rules are flushed so the htaccess is written to
    global $wp_rewrite;
    $wp_rewrite->flush_rules();
}

register_activation_hook(__FILE__, 'plugin_activate');
//actions..