Site icon Hip-Hop Website Design and Development

Multiple URL rewrite rules and get every prams

I am creating a messaging system where I have 4 sections (1)inbox (2)sent (3)draft (4)unread so I decide to go with WordPress add rewrite rules

I have already added one rewrite rule section.

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

Now I want to add one more param after the section is the ID(inbox messages id).

so for that, I add a second rewrite rule id.

add_rewrite_rule(
    'messages/inbox/([^/]*)/?$',
    'index.php?pagename=messages&id=$matches[1]&section=$matches[2]',
'top' );

if I visit https://example.com/messages/inbox I can get in query_vars

[section] => inbox 

but the issue is that if I visit https://example.com/messages/inbox/123 I can get in query_vars

[section] => 
[id] => 123

I am not getting section value, in this case, I want to check in this URL which section Is currently that’s why I need section value on this page.