Wordpress add a rewrite rule to a page to accept a GET variable

I want to rewrite

mysite.com/events/submission/test-event-01

to

mysite.com/events/submission?epl=test-event-01

This is what I have done so far without any result. I get a 404 error (mysite.com/events/submission/test-event-01). Can anyone suggest the correct rule?

add_action( 'init', 'epl_rewrite');
add_filter( 'query_vars', 'epl_query_vars');
        
function epl_rewrite()
{
    add_rewrite_rule('^submission/([^/]*)[/]?', 'index.php?pagename=submissionepl=$matches[1]', 'top');
}
        
function epl_query_vars( $query_vars )
{
    $query_vars[] = 'epl';
    return $query_vars;
}

Note:

  1. Permalinks are re-saved to flush the rewrite rules.
  2. mysite.com/events/submission page is already added.

Thank you in advance.

Topic query-variable rewrite-rules Wordpress

Category Web


Since 'submission' is a child page of 'events', the rewrite rule should include the parent path

add_rewrite_rule('events/([^/]*)/submission/?', 'index.php?pagename=events/submission&epl=$matches[1]', 'top');

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.