• Hi,

    I am desperately trying since a few days to use the following rewrite rule.

    The URL should be somtething like this:
    https://www.example.com/parameter/custom-page

    The problem is that the parameter should be before the pagename as it is user-friendlier in this case.

    The RegExp I used is: (.?.+?)/([^/]+)/custom-page/?$
    That expression works fine with a RegExp tester but it seems like WordPress doesn’t use it. According to the plugin “Rewrite Rules Inspector” its registered but not used for the URL.

    Hope someone can help me as I don’t have a clue whats wrong at the moment ??

    Thanks very much in advance
    Ben

Viewing 3 replies - 1 through 3 (of 3 total)
  • In add_rewrite_rule(), the third parameter should be set to ‘top’. Is that the case for your rule?

    Example:

    add_rewrite_rule(
        '^nutrition/([^/]*)/([^/]*)/?',
        'index.php?page_id=12&food=$matches[1]&variety=$matches[2]',
        'top'
    );

    Thread Starter BenBensen

    (@benbensen)

    Thanks for the answer. Yeah it’s set to ‘top’.

    Can you post your add_rewrite_rule() exactly as it appears in your theme or plugin?

    Also, have you tested on a fresh WP install, with no plugins and the default theme, to rule out any conflicts?

    The more information you can provide (other rewrite rules that are registered; plugins installed; version of WordPress) the more likely someone can help you track down the issue.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Rewrite rule doesn't work’ is closed to new replies.