2
add_rewrite_rule(
    '^invite/([^/]+)',
    'index.php?pagename=invite&iid=$matches[1]',
    'top'
);

The "internal" rewrite rule above will route traffic through index.php using the pagename argument (which necessitates having a page with slug invite).

I want to direct routing to invite.php (which will render an ICS calendar file and force download).

I looked into the below implementation, however, this appears to directly modify .htaccess file. My site is using nginx so this won't work.

add_rewrite_rule(
    '^invite/([^/]+)',
    'invite.php?iid=$matches[1]',
    'top'
);
6
  • This answer might help you.
    – Milo
    Sep 28, 2017 at 15:59
  • Thanks. That answer run a new WP_Query under their specific conditions. In my case, I am diverting to a file that has non-WP logic, not tied to any post type etc. My invite.php sets a Content-Disposition: attachment; filename=invite.ics header to force a download and echo's a var (which becomes the downloaded files content) Sep 28, 2017 at 16:15
  • The contents of that if condition are irrelevant to the answer, just remove that code and put your own logic inside.
    – Milo
    Sep 28, 2017 at 16:19
  • Right. The logic I need within parse_query to use invite.php isn't clear to me. Thanks for the answer but it doesn't really solve the issue Sep 28, 2017 at 16:23
  • 1
    or just remove invite.php entirely and put whatever code is in that file within the function instead.
    – Milo
    Sep 28, 2017 at 16:26

1 Answer 1

-2
add_action('parse_query', function(&$wp_query) {

    if (array_key_exists('iid', $wp_query->query_vars) && $wp_query->query['pagename'] === 'invite') {

        $iid = get_query_var('iid');

        // Do some stuff

        exit();

    }

    return;

});
1
  • 1
    what is that? a blob of code by itself is not an answer Sep 28, 2017 at 17:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.