WordPress.org

Make WordPress Core

Opened 2 months ago

Last modified 2 months ago

#50943 new defect (bug)

add_rewrite_rule() sample codes don't work for passing multiple params

Reported by: shahryarhn Owned by:
Milestone: Awaiting Review Priority: normal
Severity: critical Version: 5.5
Component: Rewrite Rules Keywords:
Focuses: Cc:

Description

Hi
I'd found out a new bug in wordpress v5.5 (latest release update), and its related to rewrite rules.
Even sample codes in following page won't work for passing multiple params in url mentioned in "Using Custom Templates with custom querystring" section:
https://codex.wordpress.org/Rewrite_API/add_rewrite_rule

I'd tried every possible ways to achieve that, but I couldn't. I think it's a bug. I hope this is not a false report. if it is, sorry for that and could you help me.

I using this code:

<?php
add_action('init', function ()
{
    add_rewrite_tag('%page%', '([^&]+)');
    add_rewrite_tag('%args%', '([^&]+)');

    add_rewrite_rule(
        '^auth/?([^/]*)/?$',
        'index.php?pagename=auth&page=$matches[1]',
        'top'
    );
    add_rewrite_rule(
        '^profile/([^/]*)/?([^/]*)/?$',
        'index.php?pagename=profile&page=$matches[1]&args=$matches[2]',
        'top'
    );
}, 10, 0);

as you can see, I have two page with two different rewrite rules.

in wordpress v5.4 it works very well, but in new version, it don't.

Best regards

Change History (1)

#1 @SergeyBiryukov
2 months ago

  • Summary changed from bug in rewrite rules to add_rewrite_rule() sample codes don't work for passing multiple params
Note: See TracTickets for help on using tickets.